Class: ChainOptions::Builder

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

Overview

A simple helper class to set multiple chain options after another by using a ‘set NAME, VALUE` syntax instead of having to use constructs like

instance = instance.NAME(VALUE)
instance = instance.NAME2(VALUE2) if XY
...

Instance Method Summary collapse

Constructor Details

#initialize(initial_instance, &block) ⇒ Builder

Returns a new instance of Builder.



13
14
15
16
17
# File 'lib/chain_options/builder.rb', line 13

def initialize(initial_instance, &block)
  @instance = initial_instance
  ChainOptions::Util.instance_eval_or_call(self, &block)
  result
end

Instance Method Details

#resultObject



19
20
21
# File 'lib/chain_options/builder.rb', line 19

def result
  @instance
end

#set(option_name, *value, &block) ⇒ Object



23
24
25
# File 'lib/chain_options/builder.rb', line 23

def set(option_name, *value, &block)
  @instance = @instance.send(option_name, *value, &block)
end