Class: Bemer::Pipeline::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/bemer/pipeline/handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(templates) ⇒ Handler

Returns a new instance of Handler.



8
9
10
11
12
13
# File 'lib/bemer/pipeline/handler.rb', line 8

def initialize(templates)
  @priorities = Pipeline::MODES.map { |mode| [mode, {}] }.to_h
  @container  = Pipeline::MODES.map { |mode| [mode, []] }.to_h

  prioritize(templates)
end

Instance Method Details

#apply(mode, current_template, node, **params) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/bemer/pipeline/handler.rb', line 27

def apply(mode, current_template, node, **params)
  return unless allowable_mode?(mode) && compatible_modes?(mode, current_template.mode)

  if current_template.mode.eql?(mode)
    apply_next(current_template, node, params)
  else
    apply_template(mode, node, params)
  end
end

#apply!(mode, node) ⇒ Object



15
16
17
18
19
# File 'lib/bemer/pipeline/handler.rb', line 15

def apply!(mode, node)
  return if node.applied_modes[mode].present? || !allowable_mode?(mode)

  apply_template!(mode, node)
end

#apply_next(current_template, node, **params) ⇒ Object



21
22
23
24
25
# File 'lib/bemer/pipeline/handler.rb', line 21

def apply_next(current_template, node, **params)
  position = priorities[current_template.mode][current_template.object_id] + 1

  apply_template(current_template.mode, node, position, params)
end