Class: AttrJson::NestedAttributes::Builder
- Inherits:
-
Object
- Object
- AttrJson::NestedAttributes::Builder
- Defined in:
- lib/attr_json/nested_attributes/builder.rb
Overview
Implementation of build_
methods, called by the build_
methods
AttrJson::NestedAttributes adds.
Instance Attribute Summary collapse
-
#attr_def ⇒ Object
readonly
Returns the value of attribute attr_def.
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #build(params = {}) ⇒ Object
-
#initialize(model, attr_name) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(model, attr_name) ⇒ Builder
Returns a new instance of Builder.
10 11 12 13 |
# File 'lib/attr_json/nested_attributes/builder.rb', line 10 def initialize(model, attr_name) @model, @attr_name = model, attr_name, @attr_def = model.class.attr_json_registry[attr_name] end |
Instance Attribute Details
#attr_def ⇒ Object (readonly)
Returns the value of attribute attr_def.
8 9 10 |
# File 'lib/attr_json/nested_attributes/builder.rb', line 8 def attr_def @attr_def end |
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
8 9 10 |
# File 'lib/attr_json/nested_attributes/builder.rb', line 8 def attr_name @attr_name end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/attr_json/nested_attributes/builder.rb', line 8 def model @model end |
Instance Method Details
#build(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/attr_json/nested_attributes/builder.rb', line 15 def build(params = {}) if attr_def.array_type? model.send("#{attr_name}=", (model.send(attr_name) || []) + [params]) return model.send("#{attr_name}").last else model.send("#{attr_name}=", params) return model.send("#{attr_name}") end end |