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.17.0 lib/fitting/documentation.rb
fitting-2.16.1 lib/fitting/documentation.rb
fitting-2.16.0 lib/fitting/documentation.rb
fitting-2.15.0 lib/fitting/documentation.rb
fitting-2.14.1 lib/fitting/documentation.rb
fitting-2.14.0 lib/fitting/documentation.rb
fitting-2.13.1 lib/fitting/documentation.rb
fitting-2.13.0 lib/fitting/documentation.rb
fitting-2.12.1 lib/fitting/documentation.rb
fitting-2.12.0 lib/fitting/documentation.rb
fitting-2.11.0 lib/fitting/documentation.rb
fitting-2.10.0 lib/fitting/documentation.rb
fitting-2.9.1 lib/fitting/documentation.rb
fitting-2.9.0 lib/fitting/documentation.rb
fitting-2.8.1 lib/fitting/documentation.rb
fitting-2.8.0 lib/fitting/documentation.rb
fitting-2.7.2 lib/fitting/documentation.rb
fitting-2.7.1 lib/fitting/documentation.rb
fitting-2.7.0 lib/fitting/documentation.rb
fitting-2.6.0 lib/fitting/documentation.rb