Class: SimpleBuilder
- Inherits:
-
Object
- Object
- SimpleBuilder
- Defined in:
- lib/simple_builder.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
-
.build(params, &block) ⇒ Object
end of Contract.
- .update(object, params) ⇒ Object
Instance Method Summary collapse
- #build! ⇒ Object (also: #update!)
-
#initialize(params, object = nil, &block) ⇒ SimpleBuilder
constructor
A new instance of SimpleBuilder.
-
#new_instance ⇒ Object
Builder Contract:.
- #set_attributes ⇒ Object
Constructor Details
#initialize(params, object = nil, &block) ⇒ SimpleBuilder
Returns a new instance of SimpleBuilder.
6 7 8 9 10 11 12 |
# File 'lib/simple_builder.rb', line 6 def initialize params, object = nil, &block self.params = params if block_given? yield self end self.object = object || new_instance end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
4 5 6 |
# File 'lib/simple_builder.rb', line 4 def object @object end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/simple_builder.rb', line 4 def params @params end |
Class Method Details
.build(params, &block) ⇒ Object
end of Contract
22 23 24 |
# File 'lib/simple_builder.rb', line 22 def self.build params, &block new(params, &block).build! end |
.update(object, params) ⇒ Object
26 27 28 |
# File 'lib/simple_builder.rb', line 26 def self.update object, params new(params, object).update! end |
Instance Method Details
#build! ⇒ Object Also known as: update!
30 31 32 33 34 |
# File 'lib/simple_builder.rb', line 30 def build! set_attributes object.save object end |
#new_instance ⇒ Object
Builder Contract:
15 16 |
# File 'lib/simple_builder.rb', line 15 def new_instance end |
#set_attributes ⇒ Object
18 19 |
# File 'lib/simple_builder.rb', line 18 def set_attributes end |