Class: Hospodar::Builder::Strategies::Mount
- Inherits:
-
Object
- Object
- Hospodar::Builder::Strategies::Mount
- Defined in:
- lib/hospodar/builder/strategies/mount.rb
Overview
Creates objects and provides readers on target objects
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
-
#step_id ⇒ Object
readonly
Returns the value of attribute step_id.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #call ⇒ Object
- #create_object(init_proc, id) ⇒ Object
- #handle_exception(exc, id, init_attrs) ⇒ Object
- #init_attrs_for(id) ⇒ Object
- #init_params ⇒ Object
-
#initialize(strategy, pipe, target, step) ⇒ Mount
constructor
A new instance of Mount.
- #instantiate_objects(yielder) ⇒ Object
Constructor Details
#initialize(strategy, pipe, target, step) ⇒ Mount
10 11 12 13 14 15 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 10 def initialize(strategy, pipe, target, step) @strategy = strategy @pipe = pipe @target = target @step = step end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
8 9 10 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 8 def object @object end |
#pipe ⇒ Object (readonly)
Returns the value of attribute pipe.
8 9 10 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 8 def pipe @pipe end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
8 9 10 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 8 def step @step end |
#step_id ⇒ Object (readonly)
Returns the value of attribute step_id.
8 9 10 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 8 def step_id @step_id end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
8 9 10 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 8 def strategy @strategy end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 8 def target @target end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 17 def call Enumerator.new do |yielder| instantiate_objects(yielder) end end |
#create_object(init_proc, id) ⇒ Object
34 35 36 37 38 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 34 def create_object(init_proc, id) init_proc.call(*init_attrs_for(id)) rescue StandardError => e handle_exception(e, id, init_attrs_for(id)) end |
#handle_exception(exc, id, init_attrs) ⇒ Object
48 49 50 51 52 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 48 def handle_exception(exc, id, init_attrs) exception = Hospodar::Builder.create_init_error(exc, id, init_attrs) target.exception = exception raise exception unless target.ignore_exceptions? end |
#init_attrs_for(id) ⇒ Object
40 41 42 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 40 def init_attrs_for(id) Array(init_params[id.to_sym]) end |
#init_params ⇒ Object
44 45 46 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 44 def init_params @init_params ||= strategy.call end |
#instantiate_objects(yielder) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hospodar/builder/strategies/mount.rb', line 23 def instantiate_objects(yielder) pipe.each do |id, init_proc| @step_id = id object = create_object(init_proc, id) next if object.nil? && target.ignore_exceptions? target.define_singleton_method(id.title.to_sym) { object } yielder << [object, id] end end |