Module: ActiveModel::AttributeFilters::ClassMethods
- Defined in:
- lib/attribute-filters/dsl_sets.rb,
lib/attribute-filters/dsl_filters.rb
Overview
This module contains class methods that create DSL for managing attribute sets.
Instance Method Summary collapse
- #attribute_set(*args) ⇒ Object (also: #attributes_that_are, #attributes_that, #attributes_are, #attributes_for, #attributes_set, #properties_that)
-
#attribute_sets ⇒ Hash{Symbol => AttributeSet<String>}
(also: #attributes_sets, #properties_sets)
Gets all the defined attribute sets.
-
#attributes_to_sets ⇒ Hash{String => AttributeSet<Symbol>}
(also: #attribute_sets_map)
Gets all the defined attribute set names hashed by attribute names.
- #filter_attribute(*args) ⇒ Object (also: #the_attribute, #add_attribute_to_set, #add_attribute_to_sets, #attribute_to_set, #filtered_attribute, #filtered_attributes)
-
#filter_virtual_attributes_that_changed? ⇒ Boolean
Gets the internal flag that causes to check virtual attributes for changes when selecting attributes for filtering.
-
#filter_virtual_attributes_that_have_changed
(also: #filter_virtual_attributes_that_changed, #filter_changed_virtual_attributes)
Sets the internal flag that causes to check virtual attributes for changes when selecting attributes for filtering.
- #treat_as_real(*args) ⇒ Object (also: #treat_attribute_as_real, #treat_attributes_as_real)
Instance Method Details
#attribute_set ⇒ Hash{Symbol => AttributeSet<String>} #attribute_set(set_name) ⇒ AttributeSet<String> #attribute_set(set_name, *attribute_names) ⇒ nil #attribute_set(associations) ⇒ nil #attribute_set(associations, *attribute_names) ⇒ nil Also known as: attributes_that_are, attributes_that, attributes_are, attributes_for, attributes_set, properties_that
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/attribute-filters/dsl_sets.rb', line 115 def attribute_set(*args) AttributeFiltersHelpers.check_wanted_methods(self) case args.size when 0 attribute_sets when 1 first_arg = args.first if first_arg.is_a?(Hash) first_arg.each_pair { |k, v| attribute_set(k, v) } nil else attribute_sets[first_arg.to_sym] end else first_arg = args.shift if first_arg.is_a?(Hash) first_arg.each_pair do |k, v| attribute_set(k, v, args) end else set_name = first_arg.to_sym atrs = args.flatten.compact.map{|a|a.to_s}.freeze atrs.each do |atr_name| __attributes_to_sets_map[atr_name] ||= ActiveModel::AttributeSet.new __attributes_to_sets_map[atr_name] << set_name end __attribute_sets[set_name] ||= ActiveModel::AttributeSet.new __attribute_sets[set_name] << atrs end nil end end |
#attribute_sets ⇒ Hash{Symbol => AttributeSet<String>} Also known as: attributes_sets, properties_sets
Use key method explicitly to check if the given set exists. The hash returned by this method will always return ActiveModel::AttributeSet object. If there is no such set defined then the returned, matching set will be empty.
Gets all the defined attribute sets.
222 223 224 225 226 |
# File 'lib/attribute-filters/dsl_sets.rb', line 222 def attribute_sets d = __attribute_sets.dup d.default = ActiveModel::AttributeSet.new d end |
#attributes_to_sets ⇒ Hash{String => AttributeSet<Symbol>} Also known as: attribute_sets_map
Use key method explicitly to check if the given attribute is assigned to any set. The hash returned by this method will always return ActiveModel::AttributeSet object. If the attribute is not assigned to any set then the returned, matching set will be empty.
Gets all the defined attribute set names hashed by attribute names.
235 236 237 238 239 |
# File 'lib/attribute-filters/dsl_sets.rb', line 235 def attributes_to_sets d = __attributes_to_sets_map.dup d.default = ActiveModel::AttributeSet.new d end |
#filter_attribute ⇒ Hash{String => AttributeSet<Symbol>} #filter_attribute(attribute_name) ⇒ AttributeSet<Symbol> #filter_attribute(attribute_name, *set_names) ⇒ nil #filter_attribute(associations) ⇒ nil #filter_attribute(associations, *set_names) ⇒ nil Also known as: the_attribute, add_attribute_to_set, add_attribute_to_sets, attribute_to_set, filtered_attribute, filtered_attributes
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/attribute-filters/dsl_sets.rb', line 182 def filter_attribute(*args) AttributeFiltersHelpers.check_wanted_methods(self) case args.size when 0 attributes_to_sets when 1 first_arg = args.first if first_arg.is_a?(Hash) first_arg.each_pair { |k, v| filter_attribute(k, v) } nil else attributes_to_sets[first_arg.to_s] end else first_arg = args.shift if first_arg.is_a?(Hash) first_arg.each_pair do |k, v| filter_attribute(k, v, args) end else first_arg = first_arg.to_s args.flatten.compact.each do |set_name| attribute_set(set_name, first_arg) end end nil end end |
#filter_virtual_attributes_that_changed? ⇒ Boolean
Gets the internal flag that causes to check virtual attributes for changes when selecting attributes for filtering.
207 208 209 |
# File 'lib/attribute-filters/dsl_filters.rb', line 207 def filter_virtual_attributes_that_changed? !!@filter_virtual_attributes_that_changed end |
#filter_virtual_attributes_that_have_changed Also known as: filter_virtual_attributes_that_changed, filter_changed_virtual_attributes
This method returns an undefined value.
Sets the internal flag that causes to check virtual attributes for changes when selecting attributes for filtering.
198 199 200 |
# File 'lib/attribute-filters/dsl_filters.rb', line 198 def filter_virtual_attributes_that_have_changed @filter_virtual_attributes_that_changed = true end |
#treat_as_real(*attributes) #treat_as_real ⇒ AttributeSet Also known as: treat_attribute_as_real, treat_attributes_as_real
187 188 189 190 191 |
# File 'lib/attribute-filters/dsl_filters.rb', line 187 def treat_as_real(*args) return __treat_as_real.dup if args.blank? __treat_as_real << args.flatten.compact.map { |atr| atr.to_s } nil end |