Class: Rundock::Builder::HookBuilder

Inherits:
Base show all
Defined in:
lib/rundock/builder/hook_builder.rb

Constant Summary collapse

DEFAULT_HOOKS_FILE_PATH =
'./hooks.yml'
HookStructureError =
Class.new(StandardError)

Constants inherited from Base

Base::BuilderNotImplementedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ HookBuilder

Returns a new instance of HookBuilder.



11
12
13
14
# File 'lib/rundock/builder/hook_builder.rb', line 11

def initialize(options)
  super(options)
  @enable_hooks = {}
end

Instance Attribute Details

#enable_hooksObject

Returns the value of attribute enable_hooks.



9
10
11
# File 'lib/rundock/builder/hook_builder.rb', line 9

def enable_hooks
  @enable_hooks
end

Instance Method Details

#build(enables, hook_attributes) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rundock/builder/hook_builder.rb', line 16

def build(enables, hook_attributes)
  if enables.blank?
    Logger.info('Empty hook is specified.')
    return []
  elsif hook_attributes.nil? && @options[:hooks]
    if FileTest.exist?(@options[:hooks])
      hooks_file = @options[:hooks]
      Logger.info("hooks file is #{hooks_file}")
    elsif FileTest.exist?(DEFAULT_HOOKS_FILE_PATH)
      Logger.warn("hooks file is not found. use #{DEFAULT_HOOKS_FILE_PATH}")
      hooks_file = DEFAULT_HOOKS_FILE_PATH
    else
      Logger.warn("Hook path is not available. (#{@options[:hooks]})")
      return []
    end
  elsif hook_attributes.nil?
    Logger.warn("Hook source is not found. (enables:#{enables.join(',')})") unless enables.empty?
    return []
  end

  if hooks_file
    build_from_attributes(YAML.load_file(hooks_file).deep_symbolize_keys, enables)
  else
    build_from_attributes(hook_attributes, enables)
  end
end

#rebuild(node_attributes) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/rundock/builder/hook_builder.rb', line 43

def rebuild(node_attributes)
  hooks = []

  node_attributes.each do |k, v|
    hooks = Rundock::HookFactory.instance(v[:hook_type]).create(k.to_s, v)
  end

  hooks
end