Module: ActiveModel::AttributeSet::Enumerable
- Defined in:
- lib/attribute-filters/attribute_set_enum.rb
Instance Method Summary collapse
-
#each_name_value(am_object, no_presence_check = false) ⇒ void, AttributeSet::Enumerator
Iterates through the name and value of each attribute found in a set.
-
#select_accessible(binding = nil) ⇒ AttributeSet::Enumerator, AttributeSet
Selects attributes that have setters and getters.
Instance Method Details
#each_name_value(am_object, no_presence_check = false) ⇒ void, AttributeSet::Enumerator
Iterates through the name and value of each attribute found in a set. If the attribute has no getter method in the context of the given object, it is not evaluated.
60 61 62 63 64 65 66 67 |
# File 'lib/attribute-filters/attribute_set_enum.rb', line 60 def each_name_value(am_object, no_presence_check = false) block_given? or return AttributeSet::Enumerator.new(self, :each_name_value, am_object, no_presence_check) if no_presence_check each { |name| yield(name, am_object.public_send(name)) } else each { |name| yield(name, am_object.public_send(name)) if am_object.respond_to?(name) } end end |
#select_accessible(binding = nil) ⇒ AttributeSet::Enumerator, AttributeSet
Selects attributes that have setters and getters.
23 24 25 26 27 28 29 |
# File 'lib/attribute-filters/attribute_set_enum.rb', line 23 def select_accessible(binding = nil) if binding.nil? select { |a| respond_to?(a) && respond_to?("#{a}=") } else select { |a| binding.respond_to?(a) && binding.respond_to?("#{a}=") } end end |