Method: ActiveModel::AttributeFilters#attributes_to_filter

Defined in:
lib/attribute-filters/dsl_filters.rb

#attributes_to_filter(set_name, process_all, no_presence_check) ⇒ AttributeSet #attributes_to_filter(attribute_set, process_all, no_presence_check) ⇒ AttributeSet

Gets names of attributes for which filters should be applied by selecting attributes that are meeting certain criteria and belong to the given attribute set.

Overloads:

  • #attributes_to_filter(set_name, process_all, no_presence_check) ⇒ AttributeSet

    Returns set of attributes (attribute name => previous_value).

    Parameters:

    • set_name (String, Symbol)

      name of a set of attributes used to get attributes

    • process_all (Boolean)

      if set then all the attributes from the attribute set are selected, not just the attributes that have changed (defaults to false)

    • no_presence_check (Boolean)

      if set then the checking whether each attribute exists will be disabled (matters only when process_all is also set) (defaults to false)

    Returns:

    • (AttributeSet)

      set of attributes (attribute name => previous_value)

  • #attributes_to_filter(attribute_set, process_all, no_presence_check) ⇒ AttributeSet

    Returns set of attributes (attribute name => previous_value).

    Parameters:

    • attribute_set (AttributeSet)

      set of attributes used to get attributes

    • process_all (Boolean)

      if set then all the attributes from the attribute set are selected, not just the attributes that has changed (defaults to false)

    • no_presence_check (Boolean)

      if set then the checking whether each attribute exists will be disabled (matters only when process_all is also set) (defaults to false)

    Returns:

    • (AttributeSet)

      set of attributes (attribute name => previous_value)



42
43
44
45
46
47
48
49
50
51
# File 'lib/attribute-filters/dsl_filters.rb', line 42

def attributes_to_filter(set_name, process_all = false, no_presence_check = false)
  set_name.blank? and return ::ActiveModel::AttributeSet.new
  atf = set_name.is_a?(::ActiveModel::AttributeSet) ? set_name : self.class.send(:__attribute_sets)[set_name.to_sym]
  if process_all
    no_presence_check ? atf.deep_dup : atf & __all_attributes(false)
  else
    sr = self.class.send(:__attribute_filters_semi_real)
    atf & ((no_presence_check ? sr : sr.select_accessible(self)) + changes.keys)
  end
end