Module: ActiveModel::AttributeFilters::Common::Order
- Included in:
- ActiveModel::AttributeFilters::Common
- Defined in:
- lib/attribute-filters/common_filters/order.rb
Overview
This module contains attribute filters responsible for manipulating order of attribute values.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#reverse_attributes
Inverses order of attribute contents.
Methods included from FilteringRegistration
Instance Method Details
#reverse_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.
Inverses order of attribute contents.
The attrubutes are taken from the attribute set called should_be_reversed
.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/attribute-filters/common_filters/order.rb', line 28 def reverse_attributes filter_attrs_from_set(:should_be_reversed) do |atr_val, atr_name, set_obj| if set_obj.annotation(atr_name, :reverse_enumerable) atr_val.respond_to?(:reverse) ? atr_val.reverse : atr_val else AFHelpers.each_element(atr_val) do |v| v.respond_to?(:reverse) ? v.reverse : v end end end end |