Module: ActiveModel::AttributeFilters::Common
- Defined in:
- lib/attribute-filters/common_filters.rb,
lib/attribute-filters/common_filters/bare.rb,
lib/attribute-filters/common_filters/case.rb,
lib/attribute-filters/common_filters/join.rb,
lib/attribute-filters/common_filters/pick.rb,
lib/attribute-filters/common_filters/order.rb,
lib/attribute-filters/common_filters/split.rb,
lib/attribute-filters/common_filters/strip.rb,
lib/attribute-filters/common_filters/convert.rb,
lib/attribute-filters/common_filters/squeeze.rb,
lib/attribute-filters/common_filters/presence.rb
Overview
This module contains common, ready-to-use filtering methods.
Defined Under Namespace
Modules: Bare, Case, ClassMethods, Convert, Join, Order, Pick, Presence, Split, Squeeze, Strip
Instance Method Summary collapse
-
#shuffle_attributes
Randomizes order of attribute contents.
Methods included from FilteringRegistration
Methods included from Presence
Methods included from Squeeze
#squeeze_attributes, #squish_attributes
Methods included from Convert
#attributes_to_b, #attributes_to_f, #attributes_to_i, #attributes_to_numbers, #attributes_to_r, #attributes_to_s
Methods included from Strip
Methods included from Split
Methods included from Order
Methods included from Pick
Methods included from Join
Methods included from Case
#capitalize_attributes, #downcase_attributes, #fully_capitalize_attributes, #titleize_attributes, #upcase_attributes
Instance Method Details
#shuffle_attributes
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.
Randomizes order of attribute contents.
The attrubutes are taken from the attribute set called should_be_shuffled
.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/attribute-filters/common_filters/order.rb', line 63 def shuffle_attributes filter_attrs_from_set(:should_be_shuffled) do |atr_val, atr_name, set_obj| shuffle_enum, rng = set_obj.annotation(atr_name, :shuffle_enumerable, :shuffle_generator) rng = { :random => rng } if shuffle_enum if atr_val.is_a?(String) atr_val.mb_chars.split("").shuffle(rng).join else atr_val.respond_to?(:shuffle) ? atr_val.shuffle(rng) : atr_val end else AFHelpers.each_element(atr_val) do |v| if v.is_a?(String) v.mb_chars.split("").shuffle(rng).join else v.respond_to?(:shuffle) ? v.shuffle(rng) : v end end end end end |