Sha256: 7b623440574b0a792941037203582c913f89b58fe34b29b43bbe3aa430c3dc42

Contents?: true

Size: 803 Bytes

Versions: 3

Compression:

Stored size: 803 Bytes

Contents

require 'multi_json'
require 'tomograph/path'
require 'tomograph/api_blueprint/yaml'

module Tomograph
  class Tomogram
    def initialize(prefix: '', apib_path: nil, drafter_yaml_path: nil)
      @documentation = Tomograph::ApiBlueprint::Yaml.new(prefix, apib_path, drafter_yaml_path)
      @prefix = prefix
    end

    def to_hash
      @documentation.to_tomogram.map(&:to_hash)
    end

    def to_json
      MultiJson.dump(to_hash)
    end

    def find_request(method:, path:)
      path = Tomograph::Path.new(path).to_s

      @documentation.to_tomogram.find do |action|
        action.method == method && action.path.match(path)
      end
    end

    def to_resources
      @documentation.to_resources
    end

    def prefix_match?(raw_path)
      raw_path.include?(@prefix)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tomograph-2.0.1 lib/tomograph/tomogram.rb
tomograph-2.0.0 lib/tomograph/tomogram.rb
tomograph-1.2.0 lib/tomograph/tomogram.rb