Module: ActiveModel::AttributeSet::Enumerable

Included in:
ActiveModel::AttributeFilters::AttributeSetMethods, Enumerator, AttributeSetEnumerable
Defined in:
lib/attribute-filters/attribute_set_enum.rb

Instance Method Summary collapse

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.

Parameters:

  • am_object (Object)

    active model object

  • no_presence_check (Boolean) (defaults to: false)

    optional flag that if true causes enumerator not to check if a getter method exists (defaults to false – checks are done)

Returns:



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.

Parameters:

  • binding (Object) (defaults to: nil)

    optional object which should have setters and getters (default: the calling context)

Returns:



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