Class: UDAMUtils::BasePublishMapProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/udam_utils/publish_map_processor.rb

Direct Known Subclasses

WorkflowPublishMapProcessor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BasePublishMapProcessor

Returns a new instance of BasePublishMapProcessor.

Raises:

  • (RuntimeError)


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

#loggerObject

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_mapObject

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

Options Hash (options):

  • :default (Any)

    The default value to return if none of the keys are found

  • :search_keys_as_string (Boolean)


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, options = { })
  value = options[:default]
  search_keys_as_string = options[: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

Options Hash (params):

  • :config_file_path (String)


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

Options Hash (options):

  • :default (Any)

    The default value to return if none of the keys are found

  • :search_keys_as_string (Boolean)


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, options = { })
  value = options[:default]
  search_keys_as_string = options[: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