Sha256: 68d226ea24a71309d321dd1bf01180ec570276123978b5c96992906652f0c388
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require 'yaml' module Rundock module Builder class HookBuilder < Base HookStructureError = Class.new(NotImplementedError) def build(enables) if enables.blank? return [] elsif @options[:hooks] && FileTest.exist?(@options[:hooks]) hooks_file = @options[:hooks] else return [] end build_from_file(hooks_file, enables) end def build_from_attributes(attributes) return [] unless attributes.key?(:enable_hooks) build_from_file(attributes[:hooks], attributes[:enable_hooks]) end private def build_from_file(file, enables) hooks = [] allow_all = enables.include?('all') File.open(file) do |f| YAML.load_documents(f) do |y| y.each do |k, v| raise HookStructureError if !v.is_a?(Hash) || !v.key?('hook_type') next if !allow_all && !enables.include?(k) hook = Rundock::HookFactory.instance(v['hook_type']).create(k, v.deep_symbolize_keys) hooks << hook end end end hooks end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rundock-0.4.3 | lib/rundock/builder/hook_builder.rb |
rundock-0.4.2 | lib/rundock/builder/hook_builder.rb |