Sha256: b256d2f3b8bd4d19945a38e95ef8272f15e6a5017038a19f8706a058bb00ad19

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module Fitting
  class Records
    class Documented
      class Request
        def initialize(tomogram_request, white_list)
          @tomogram_request = tomogram_request
          @white_list = white_list
        end

        def method
          @method ||= @tomogram_request['method']
        end

        def path
          @path ||= @tomogram_request['path']
        end

        def json_schema
          @json_schema ||= @tomogram_request['json_schema']
        end

        def responses
          @responses ||= groups.map do |group|
            {
              'status' => group[0],
              'json_schemas' => group[1].map { |subgroup| subgroup['body'] }
            }
          end
        end

        def white
          @white ||= white?
        end

        private

        def white?
          return true if @white_list == nil
          return false if @white_list[path.to_s] == nil
          return true if @white_list[path.to_s] == []
          return true if @white_list[path.to_s].include?(method)
          false
        end

        def groups
          @groups ||= @tomogram_request['responses'].group_by do |tomogram_response|
            tomogram_response['status']
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fitting-2.4.1 lib/fitting/records/documented/request.rb
fitting-2.4.0 lib/fitting/records/documented/request.rb
fitting-2.3.0 lib/fitting/records/documented/request.rb