File: exclusion.rb

package info (click to toggle)
ruby-json-spec 1.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: ruby: 1,059; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 515 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module JsonSpec
  module Exclusion
    extend self

    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

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

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