Module: ActiveModel::AttributeFilters::Common::Presence

Included in:
ActiveModel::AttributeFilters::Common
Defined in:
lib/attribute-filters/common_filters/presence.rb

Overview

This module contains attribute filters responsible for manipulating presence of attribute values.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from FilteringRegistration

#filtering_method

Instance Method Details

#fill_attributes

Note:

If a value of currently processed attribute is an array then any element of the array is changed. The same with hash (its values are changed).

This method returns an undefined value.

Presences-up attributes that are blank with nil or the given values.

The attrubutes are taken from the attribute set called should_be_filled.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/attribute-filters/common_filters/presence.rb', line 28

def fill_attributes
  filter_attrs_from_set(:should_be_filled, :process_blank) do |atr_val, atr_name, set_obj|
    if set_obj.annotation(atr_name, :fill_enumerable)
      if atr_val.blank? || set_obj.annotation(atr_name, :fill_any)
        set_obj.annotation(atr_name, :fill_value)
      else
        atr_val
      end
    else
      AFHelpers.each_element(atr_val) do |v|
        if v.blank? || set_obj.annotation(atr_name, :fill_any)
          set_obj.annotation(atr_name, :fill_value)
        else
          v
        end
      end
    end
  end
end