Class: Hospodar::Builder::Strategies::Mount

Inherits:
Object
  • Object
show all
Defined in:
lib/hospodar/builder/strategies/mount.rb

Overview

Creates objects and provides readers on target objects

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#objectObject (readonly)

Returns the value of attribute object.



8
9
10
# File 'lib/hospodar/builder/strategies/mount.rb', line 8

def object
  @object
end

#pipeObject (readonly)

Returns the value of attribute pipe.



8
9
10
# File 'lib/hospodar/builder/strategies/mount.rb', line 8

def pipe
  @pipe
end

#stepObject (readonly)

Returns the value of attribute step.



8
9
10
# File 'lib/hospodar/builder/strategies/mount.rb', line 8

def step
  @step
end

#step_idObject (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

#strategyObject (readonly)

Returns the value of attribute strategy.



8
9
10
# File 'lib/hospodar/builder/strategies/mount.rb', line 8

def strategy
  @strategy
end

#targetObject (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

#callObject



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_paramsObject



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