Sha256: fc69f78be5d6a50453e8f30ed5cd617d4295f55b2a0f2a3085debe7cd120c633

Contents?: true

Size: 594 Bytes

Versions: 2

Compression:

Stored size: 594 Bytes

Contents

class << RSpec::OpenAPI::HashHelper = Object.new
  def paths_to_all_fields(obj)
    case obj
    when Hash
      obj.each.flat_map do |k, v|
        k = k.to_s
        [[k]] + paths_to_all_fields(v).map { |x| [k, *x] }
      end
    else
      []
    end
  end

  def matched_paths(obj, selector)
    selector_parts = selector.split('.').map(&:to_s)
    selectors = paths_to_all_fields(obj).select do |key_parts|
      key_parts.size == selector_parts.size && key_parts.zip(selector_parts).all? do |kp, sp|
        kp == sp || (sp == '*' && kp != nil)
      end
    end
    selectors
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-openapi-0.7.1 lib/rspec/openapi/hash_helper.rb
rspec-openapi-0.7.0 lib/rspec/openapi/hash_helper.rb