refactor macro

master
Kanezoh 2021-06-17 11:27:34 +09:00
parent 1f08db49c9
commit f36767ad7f
1 changed files with 2 additions and 13 deletions

View File

@ -41,19 +41,7 @@ class MechanizeCr::Form
{% for singular, index in ["field", "radiobutton"] %} {% for singular, index in ["field", "radiobutton"] %}
{% plural = "#{singular.id}s" %} {% plural = "#{singular.id}s" %}
def {{plural.id}}_with(criteria) def {{plural.id}}_with(criteria)
value = Hash(String,String).new {{plural.id}}_with(criteria){}
if String === criteria
value = {"name" => criteria}
else
# TODO
# when args whose type isn't String is given
end
f = {{plural.id}}.select do |elm|
value.all? do |k,v|
v === elm.name
end
end
f.empty? ? nil : f
end end
def {{plural.id}}_with(criteria, &block) def {{plural.id}}_with(criteria, &block)
@ -69,6 +57,7 @@ class MechanizeCr::Form
v === elm.name v === elm.name
end end
end end
return nil if f.empty?
yield f yield f
f f
end end