class JsonRspecMatchMaker::TargetValue
Handles fetching the target value from the target object
Constants
- NUMBER
Attributes
error_key[R]
value[R]
Public Class Methods
new(key, target)
click to toggle source
# File lib/json_rspec_match_maker/target_value.rb, line 10 def initialize(key, target) @error_key = key @value = value_for_key(key, target) end
Public Instance Methods
==(other)
click to toggle source
# File lib/json_rspec_match_maker/target_value.rb, line 15 def ==(other) raise ArgumentError unless other.is_a? ExpectedValue other.value == value end
Private Instance Methods
value_for_key(key, json)
click to toggle source
# File lib/json_rspec_match_maker/target_value.rb, line 22 def value_for_key(key, json) value = key.split('.').reduce(json) do |j, k| k.match?(NUMBER) ? (j[k.to_i] || {}) : j.fetch(k, {}) end value == {} ? nil : value end