Class: UDAMUtils::BasePublishMapProcessor
- Inherits:
-
Object
- Object
- UDAMUtils::BasePublishMapProcessor
- Defined in:
- lib/udam_utils/publish_map_processor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#logger ⇒ Object
self.
Class Method Summary collapse
- .process(params = { }) ⇒ Object
-
.publish_map ⇒ Object
publish_map.
-
.publish_map=(value) ⇒ Object
publish_map=.
- .search_hash(hash, keys, options = { }) ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ BasePublishMapProcessor
constructor
A new instance of BasePublishMapProcessor.
- #load_configuration_from_file(params = { }) ⇒ Object
- #search_hash(hash, keys, options = { }) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ BasePublishMapProcessor
Returns a new instance of BasePublishMapProcessor.
43 44 45 46 47 48 49 |
# File 'lib/udam_utils/publish_map_processor.rb', line 43 def initialize(params = {}) @logger = params[:logger] || Logger.new(params[:log_to] || STDOUT) load_configuration_from_file(params) @publish_maps ||= @publish_map || params[:publish_maps] || params[:publish_map] raise RuntimeError, "Missing or Empty @publish_maps.\n Check your configuration in #{options[:config_file_path]}" unless (@publish_maps.is_a?(Array) and !@publish_maps.empty?) end |
Instance Attribute Details
#logger ⇒ Object
self
41 42 43 |
# File 'lib/udam_utils/publish_map_processor.rb', line 41 def logger @logger end |
Class Method Details
.process(params = { }) ⇒ Object
17 18 19 |
# File 'lib/udam_utils/publish_map_processor.rb', line 17 def process(params = { }) #new(params).process end |
.publish_map ⇒ Object
publish_map
15 |
# File 'lib/udam_utils/publish_map_processor.rb', line 15 def publish_map; @publish_map end |
.publish_map=(value) ⇒ Object
publish_map=
14 |
# File 'lib/udam_utils/publish_map_processor.rb', line 14 def publish_map=(value); @publish_map = value end |
.search_hash(hash, keys, options = { }) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/udam_utils/publish_map_processor.rb', line 26 def search_hash(hash, keys, = { }) value = [:default] search_keys_as_string = [:search_keys_as_string] [*keys].each do |key| value = hash[key] and break if hash.has_key?(key) if search_keys_as_string key = key.to_s value = hash[key] and break if hash.has_key?(key) end end value end |
Instance Method Details
#load_configuration_from_file(params = { }) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/udam_utils/publish_map_processor.rb', line 53 def load_configuration_from_file(params = { }) params = params.dup case params when String config_file_path = params params = { } when Hash config_file_path = params[:config_file_path] || params[:configuration_file_path] when Array case params.first when String config_file_path = params.shift params = params.first.is_a?(Hash) ? params.first : { } when Hash; params = params.shift else params = { } end end # case params return false unless config_file_path #raise ArgumentError, 'config_file_path is a required argument.' unless config_file_path raise "Configuration File Not Found. '#{config_file_path}'" unless File.exists?(config_file_path) logger.debug { "Loading Configuration From File. #{config_file_path}"} #require config_file_path eval(File.open(config_file_path, 'r').read) end |
#search_hash(hash, keys, options = { }) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/udam_utils/publish_map_processor.rb', line 86 def search_hash(hash, keys, = { }) value = [:default] search_keys_as_string = [:search_keys_as_string] [*keys].each do |key| value = hash[key] and break if hash.has_key?(key) if search_keys_as_string key = key.to_s value = hash[key] and break if hash.has_key?(key) end end value end |