Module: JsonAssert::Exclusion

Extended by:
Exclusion
Included in:
Assertions, Exclusion
Defined in:
lib/json_assert/exclusions.rb

Instance Method Summary collapse

Instance Method Details

#exclude_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/json_assert/exclusions.rb', line 18

def exclude_key?(key)
  excluded_keys.include?(key)
end

#exclude_keys(ruby) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/json_assert/exclusions.rb', line 5

def exclude_keys(ruby)
  case ruby
  when Hash
    ruby.sort.inject({}) do |hash, (key, value)|
      hash[key] = exclude_keys(value) unless exclude_key?(key)
      hash
    end
  when Array
    ruby.map{|v| exclude_keys(v) }
  else ruby
  end
end

#excluded_keysObject



22
23
24
# File 'lib/json_assert/exclusions.rb', line 22

def excluded_keys
  @excluded_keys ||= Set.new(JsonAssert.excluded_keys)
end