Class: Abstract::Builder

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

Overview

Abstract::Builder class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Abstract::Builder

Define attribute writers to Abstract::Builder instance according to

existing accessors of Abstract::Object instance

Parameters:

  • object (String)
    • Abstract::Object.class.name



57
58
59
60
61
62
63
64
# File 'lib/abstracts.rb', line 57

def initialize(object)
  @object = Class.const_get(object).new
  @object.attrs.each do |attr|
    define_singleton_method "#{attr}=" do |param|
      @object.public_send("#{attr}=", param)
    end
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



43
44
45
# File 'lib/abstracts.rb', line 43

def object
  @object
end

Class Method Details

.build {|builder| ... } ⇒ AbstractObject

Create an instance of Abstract::Object class and yield block to it

Yields:

  • (builder)

Returns:

  • (AbstractObject)
    • Abstract::Object class instance



47
48
49
50
51
# File 'lib/abstracts.rb', line 47

def self.build
  builder = new(@build_class)
  yield builder if block_given?
  builder.object
end