class Rundock::Builder::HookBuilder
Constants
- DEFAULT_HOOKS_FILE_PATH
- HookStructureError
Attributes
enable_hooks[RW]
Public Class Methods
new(options)
click to toggle source
Calls superclass method
Rundock::Builder::Base::new
# File lib/rundock/builder/hook_builder.rb, line 11 def initialize(options) super(options) @enable_hooks = {} end
Public Instance Methods
build(enables, hook_attributes)
click to toggle source
# 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.info("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)
click to toggle source
# 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
Private Instance Methods
build_from_attributes(attributes, enables)
click to toggle source
# File lib/rundock/builder/hook_builder.rb, line 55 def build_from_attributes(attributes, enables) hooks = [] allow_all = enables.include?('all') attributes.each do |k, v| raise HookStructureError unless v.is_a?(Hash) next if !allow_all && !enables.include?(k.to_s) @enable_hooks[k] = v hooks << Rundock::HookFactory.instance(v[:hook_type]).create(k.to_s, v) end Logger.warn('Empty hook is detected. Please verity hooks file and scenario file.') if hooks.empty? hooks end