Class: Makery::Builder

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

Overview

makes stuff

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs

Returns:

  • (Object)

    the current value of attrs



51
52
53
# File 'lib/makery.rb', line 51

def attrs
  @attrs
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



51
52
53
# File 'lib/makery.rb', line 51

def id
  @id
end

#instantiation_methodObject

Returns the value of attribute instantiation_method

Returns:

  • (Object)

    the current value of instantiation_method



51
52
53
# File 'lib/makery.rb', line 51

def instantiation_method
  @instantiation_method
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



51
52
53
# File 'lib/makery.rb', line 51

def klass
  @klass
end

#objObject (readonly)

Returns the value of attribute obj.



52
53
54
# File 'lib/makery.rb', line 52

def obj
  @obj
end

Class Method Details

.call(*args) ⇒ Object



53
54
55
# File 'lib/makery.rb', line 53

def self.call(*args)
  new(*args).call
end

Instance Method Details

#[](attr) ⇒ Object



68
69
70
71
# File 'lib/makery.rb', line 68

def [](attr)
  a = attrs[attr]
  a.respond_to?(:call) ? a.call(self) : a
end

#callObject



57
58
59
60
61
# File 'lib/makery.rb', line 57

def call
  @obj = klass.send(instantiation_method)
  transform
  @obj
end

#transformObject



63
64
65
66
# File 'lib/makery.rb', line 63

def transform
  attrs.each { |k, v| attrs[k] = (v.respond_to?(:call) ? v.call(self) : v) }
  attrs.each { |k, v| @obj.send("#{k}=", v) }
end