Class: ConfigLogic::Overlay

Inherits:
LogicElement show all
Defined in:
lib/config_logic/overlay.rb

Constant Summary

Constants inherited from LogicElement

LogicElement::MIN_INPUTS, LogicElement::NAME, LogicElement::STATIC

Constants included from Logger::Colors

Logger::Colors::BLUE, Logger::Colors::GREEN, Logger::Colors::RED, Logger::Colors::RESET, Logger::Colors::YELLOW

Instance Attribute Summary collapse

Attributes inherited from LogicElement

#inputs, #name

Instance Method Summary collapse

Methods inherited from LogicElement

available_elements, inherited, #input_names, name_to_type, #set_input, #static?

Methods included from Logger

#log

Constructor Details

#initialize(params) ⇒ Overlay

Returns a new instance of Overlay.



5
6
7
8
9
# File 'lib/config_logic/overlay.rb', line 5

def initialize(params)
  super
  @order = params[:inputs]
  @inputs = HashWithIndifferentAccess.new(@order.to_hash)
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



3
4
5
# File 'lib/config_logic/overlay.rb', line 3

def order
  @order
end

Instance Method Details

#outputObject

merge if possible, return highest priority data if not



13
14
15
16
17
18
19
20
21
22
# File 'lib/config_logic/overlay.rb', line 13

def output
  return unless inputs_valid?
  if @inputs.values.all? { |d| d.is_a? Hash }
    @order.inject({}) do |output, input_name|
      output.deep_merge!(@inputs[input_name])
    end
  else
    @inputs[@order.last]
  end
end