class Builderator::Config::List

Extend Array with context about how its values should be merged with other configuration layers. Possible modes are:

Attributes

mode[R]

Public Class Methods

coerce(somehting, options = {}) click to toggle source
# File lib/builderator/config/list.rb, line 12
def coerce(somehting, options = {})
  return somehting if somehting.is_a?(self)
  return new(options).push(*somehting) if somehting.is_a?(Array)

  ## `somehting` is not a valid input. Just give back an instance.
  new([], options)
end
new(from = nil, **options) click to toggle source
# File lib/builderator/config/list.rb, line 23
def initialize(from = nil, **options)
  @mode = options.fetch(:mode, :union)

  merge!(from) unless from.nil?
end

Public Instance Methods

clone() click to toggle source
# File lib/builderator/config/list.rb, line 29
def clone
  self.class.new(self, :mode => mode)
end
merge!(other) click to toggle source

Combine elements with `other` according to `other`'s `mode`

# File lib/builderator/config/list.rb, line 41
def merge!(other)
  other = self.class.coerce(other)

  case other.mode
  when :override
    return false if self == other
    set(*other)

  when :union
    merged = self | other
    return false if merged == self

    set(*merged)

  else
    fail "Invalid List mode #{other.mode}!"
  end

  true
end
set(*elements) click to toggle source
# File lib/builderator/config/list.rb, line 33
def set(*elements)
  clear
  push(*elements)
end