Class: Reform::Composition
Overview
Keeps composition of models and knows how to transform a plain hash into a nested hash.
Class Method Summary collapse
-
.process_definition!(options, definition) ⇒ Object
Builder for a concrete Composition class with configurations from the form’s representer.
Instance Method Summary collapse
Methods inherited from Expose
Class Method Details
.process_definition!(options, definition) ⇒ Object
Builder for a concrete Composition class with configurations from the form’s representer.
37 38 39 40 |
# File 'lib/reform/composition.rb', line 37 def process_definition!(, definition) [definition[:on]] ||= [] [definition[:on]] << [definition[:private_name], definition.name].compact end |
Instance Method Details
#nested_hash_for(attrs) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/reform/composition.rb', line 47 def nested_hash_for(attrs) {}.tap do |hsh| attrs.each do |name, val| #obj = self.class.model_for_property(name) config = self.class.instance_variable_get(:@map)[name.to_sym] model = config[:model] method = config[:method] hsh[model] ||= {} hsh[model][method] = val end end end |
#save ⇒ Object
43 44 45 |
# File 'lib/reform/composition.rb', line 43 def save each { |model| model.save } end |