Class: ProcessSettings::Target

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/process_settings/target.rb

Constant Summary collapse

TRUE_JSON_DOC =
{}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_doc) ⇒ Target

Returns a new instance of Target.



11
12
13
# File 'lib/process_settings/target.rb', line 11

def initialize(json_doc)
  @json_doc = json_doc
end

Instance Attribute Details

#json_docObject (readonly)

Returns the value of attribute json_doc.



9
10
11
# File 'lib/process_settings/target.rb', line 9

def json_doc
  @json_doc
end

Class Method Details

.target_key_matches?(target_value, context_hash) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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_targetObject



100
101
102
# 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) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# 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

Instance Method Details

#==(rhs) ⇒ Object



24
25
26
# File 'lib/process_settings/target.rb', line 24

def ==(rhs)
  json_doc == rhs.json_doc
end

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/process_settings/target.rb', line 28

def eql?(rhs)
  self == rhs
end

#target_key_matches?(context_hash) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# 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) ⇒ Object



19
20
21
22
# 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