Class: SimpleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_builder.rb

Constant Summary collapse

VERSION =
"1.0.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#objectObject

Returns the value of attribute object.



4
5
6
# File 'lib/simple_builder.rb', line 4

def object
  @object
end

#paramsObject

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_instanceObject

Builder Contract:



15
16
# File 'lib/simple_builder.rb', line 15

def new_instance
end

#set_attributesObject



18
19
# File 'lib/simple_builder.rb', line 18

def set_attributes
end