require 'yaml' require_relative 'config/database' require_relative 'config/sneakers' require_relative 'config/aws' require_relative 'config/worker' require_relative 'config/sentry' require_relative 'config/newrelic' module Appfuel module Service module Config class << self # Returns the worker definition while allowing you to override it and # its child definition values through the options hash # # @param options [Hash] # @return Appfuel::Configuration::DefinitionDsl def definition(options = {}) definition = options.delete(:definition) || worker_definition update_definition(definition, options) end def update_definition(definition, options) options = validate_hash!(options) return definition if options.empty? [:defaults, :file, :env, :exclude, :children].each do |type| name = "definition_#{type}" send(name, definition, options[type]) if options.key?(type) end definition end private def definition_file(definition, file) definition.file(file) end def definition_defaults(definition, defaults) defaults = validate_hash!(defaults, :defaults) definition.defaults(definition.defaults.merge(defaults)) end def definition_env(definition, env) env = validate_hash!(options[:env], :env) definition.env(definition.env.merge(env)) end def definition_exclude(definition, excludes) if excludes.is_a?(String) || excludes.is_a?(Symbol) excludes = [exlcudes] end Fail "Options (excludes) must be an array" unless excludes.is_a?(Array) excludes.each do |item| definition.delete(item) end end def definition_children(definition, children) validate_hash!(children, :children).each do |key, options| update_definition(definition[key], options) end end def validate_hash!(value, key = nil) msg = "Options" msg << " (#{key})" unless key.nil? fail "#{msg} must be a hash" unless value.is_a?(Hash) value end end end end end