Class: ConfigLogic::Overlay
- Inherits:
-
LogicElement
- Object
- LogicElement
- ConfigLogic::Overlay
- 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
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Attributes inherited from LogicElement
Instance Method Summary collapse
-
#initialize(params) ⇒ Overlay
constructor
A new instance of Overlay.
-
#output ⇒ Object
merge if possible, return highest priority data if not.
Methods inherited from LogicElement
available_elements, inherited, #input_names, name_to_type, #set_input, #static?
Methods included from Logger
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
#order ⇒ Object (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
#output ⇒ Object
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 |