class ProcessSettings::Target

Constants

TRUE_JSON_DOC

Attributes

json_doc[R]

Public Class Methods

new(json_doc) click to toggle source
# File lib/process_settings/target.rb, line 11
def initialize(json_doc)
  @json_doc = json_doc
end
target_key_matches?(target_value, context_hash) click to toggle source
# File lib/process_settings/target.rb, line 81
def target_key_matches?(target_value, context_hash)
  case target_value
  when Array
    target_value.any? { |value| target_key_matches?(value, context_hash) }
  when Hash
    target_value.all? do |key, value|
      if (context_at_key = context_hash[key])
        target_key_matches?(value, context_at_key)
      end
    end
  when true, false
    target_value
  else
    target_value == context_hash
  end
end
true_target() click to toggle source
# File lib/process_settings/target.rb, line 100
def true_target
  @true_target ||= new(TRUE_JSON_DOC)
end
with_static_context(target_value, static_context_hash) click to toggle source
# File lib/process_settings/target.rb, line 33
def with_static_context(target_value, static_context_hash)
  case target_value
  when Array
    with_static_context_array(target_value, static_context_hash)
  when Hash
    with_static_context_hash(target_value, static_context_hash)
  when true, false
    !target_value == !static_context_hash
  else
    target_value == static_context_hash
  end
end

Private Class Methods

with_static_context_array(target_value, static_context_hash) click to toggle source
# File lib/process_settings/target.rb, line 48
def with_static_context_array(target_value, static_context_hash)
  target_value.any? do |value|
    with_static_context(value, static_context_hash)
  end
end
with_static_context_hash(target_value, static_context_hash) click to toggle source
# File lib/process_settings/target.rb, line 54
def with_static_context_hash(target_value, static_context_hash)
  result = target_value.reduce({}) do |hash, (key, value)|
    if static_context_hash.has_key?(key)
      context_at_key = static_context_hash[key]
      sub_value = with_static_context(value, context_at_key)
      case sub_value
      when true   # this hash entry is true, so omit it
      when false  # this hash entry is false, so hash is false
        return false
      else        # sub-key does not exist, so hash is false
        return false
      end
    else
      hash[key] = value
    end
    hash
  end

  if result.any?
    result
  else
    true
  end
end

Public Instance Methods

==(rhs) click to toggle source
# File lib/process_settings/target.rb, line 24
def ==(rhs)
  json_doc == rhs.json_doc
end
eql?(rhs) click to toggle source
# File lib/process_settings/target.rb, line 28
def eql?(rhs)
  self == rhs
end
target_key_matches?(context_hash) click to toggle source
# File lib/process_settings/target.rb, line 15
def target_key_matches?(context_hash)
  @json_doc == TRUE_JSON_DOC || self.class.target_key_matches?(@json_doc, context_hash)
end
with_static_context(static_context_hash) click to toggle source
# File lib/process_settings/target.rb, line 19
def with_static_context(static_context_hash)
  new_json_doc = self.class.with_static_context(@json_doc, static_context_hash)
  self.class.new(new_json_doc)
end