Module: StoreModel::NestedAttributes::ClassMethods
- Defined in:
- lib/store_model/nested_attributes.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#accepts_nested_attributes_for(*attributes) ⇒ Object
Enables handling of nested StoreModel::Model attributes.
-
#attribute(name, type = nil) ⇒ Object
add storemodel type of attribute if it is storemodel type.
-
#store_model_attribute_types ⇒ Object
gather storemodel attribute types on the class-level.
Instance Method Details
#accepts_nested_attributes_for(*attributes) ⇒ Object
Enables handling of nested StoreModel::Model attributes
Alternatively, use the standard Rails syntax:
Supported options:
- :allow_destroy
-
If true, destroys any members from the attributes hash with a
_destroy
key and a value that evaluates totrue
(e.g. 1, ‘1’, true, or ‘true’). This option is off by default. - :reject_if
-
Allows you to specify a Proc or a Symbol pointing to a method that checks whether a record should be built for a certain attribute hash. The hash is passed to the supplied Proc or the method and it should return either true or false. Passing
:all_blank
instead of a Proc will create a proc that will reject a record where all the attributes are blank excluding any value for_destroy
.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/store_model/nested_attributes.rb', line 48 def accepts_nested_attributes_for(*attributes) = attributes. attributes.each do |attribute| if nested_attribute_type(attribute).is_a?(Types::Base) .reverse_merge!(allow_destroy: false, update_only: false) define_store_model_attr_accessors(attribute, ) else super(*attribute, ) end end end |
#attribute(name, type = nil) ⇒ Object
add storemodel type of attribute if it is storemodel type
17 18 19 20 |
# File 'lib/store_model/nested_attributes.rb', line 17 def attribute(name, type = nil, **) store_model_attribute_types[name.to_s] = type if type.is_a?(Types::Base) super end |
#store_model_attribute_types ⇒ Object
gather storemodel attribute types on the class-level
12 13 14 |
# File 'lib/store_model/nested_attributes.rb', line 12 def store_model_attribute_types @store_model_attribute_types ||= {} end |