Sha256: 22d7852b8dc2d5c955f155592373c56102690d3dabf03a31d8a2118aa8d01243

Contents?: true

Size: 1.34 KB

Versions: 29

Compression:

Stored size: 1.34 KB

Contents

require 'multi_json'

module Fitting
  class Documentation
    def initialize(tomogram, white_list)
      @tomogram = tomogram
      @white_list = white_list
    end

    def black
      if @white_list
        all.select do |response|
          black?(response)
        end
      else
        []
      end
    end

    def white
      if @white_list
        all.select do |response|
          white?(response)
        end
      else
        all
      end
    end

    def all
      @all ||= @tomogram.to_hash.each_with_object([]) do |request, routes|
        responses(request).map do |status, indexes|
          indexes.times do |index|
            route = "#{request['method']}\t#{request['path']} #{status} #{index}"
            routes.push(route)
          end
        end
      end.uniq
    end

    def responses(request)
      request['responses'].each_with_object({}) do |response, responses|
        responses[response['status']] ||= 0
        responses[response['status']] += 1
      end
    end

    def black?(response)
      data = response.split(' ')
      data[1] && !@white_list[data[1]] || (@white_list[data[1]] != [] && !@white_list[data[1]].include?(data[0]))
    end

    def white?(response)
      data = response.split(' ')
      data[1] && @white_list[data[1]] && (@white_list[data[1]] == [] || @white_list[data[1]].include?(data[0]))
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
fitting-2.5.0 lib/fitting/documentation.rb
fitting-2.4.1 lib/fitting/documentation.rb
fitting-2.4.0 lib/fitting/documentation.rb
fitting-2.3.0 lib/fitting/documentation.rb
fitting-2.2.0 lib/fitting/documentation.rb
fitting-2.1.3 lib/fitting/documentation.rb
fitting-2.1.2 lib/fitting/documentation.rb
fitting-2.1.1 lib/fitting/documentation.rb
fitting-2.1.0 lib/fitting/documentation.rb