Module: JsonSpec::Exclusion

Extended by:
Exclusion
Included in:
Exclusion, Matchers::BeJsonEql, Matchers::IncludeJson
Defined in:
lib/json_spec/exclusion.rb

Instance Method Summary collapse

Instance Method Details

#exclude_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/json_spec/exclusion.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_spec/exclusion.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_spec/exclusion.rb', line 22

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