class Tomograph::Tomogram

Public Class Methods

new(prefix: '', drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil, openapi2_json_path: nil, openapi3_yaml_path: nil) click to toggle source
# File lib/tomograph/tomogram.rb, line 13
def initialize(prefix: '', drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil, openapi2_json_path: nil, openapi3_yaml_path: nil)
  @documentation = if tomogram_json_path
                     Tomograph::ApiBlueprint::JsonSchema.new(prefix, tomogram_json_path)
                   elsif crafter_yaml_path
                     Tomograph::ApiBlueprint::Crafter::Yaml.new(prefix, crafter_yaml_path)
                   elsif openapi2_json_path
                     Tomograph::OpenApi::OpenApi2.new(prefix, openapi2_json_path)
                   elsif openapi3_yaml_path
                     Tomograph::OpenApi::OpenApi3.new(prefix, openapi3_yaml_path)
                   else
                     Tomograph::ApiBlueprint::Drafter4::Yaml.new(prefix, drafter_yaml_path)
                   end
  @prefix = prefix
end

Public Instance Methods

find_request(method:, path:) click to toggle source
# File lib/tomograph/tomogram.rb, line 36
def find_request(method:, path:)
  path = Tomograph::Path.new(path).to_s

  to_a.find do |action|
    action.method == method && action.path.match(path)
  end
end
find_request_with_content_type(method:, path:, content_type:) click to toggle source
# File lib/tomograph/tomogram.rb, line 44
def find_request_with_content_type(method:, path:, content_type:)
  path = Tomograph::Path.new(path).to_s

  to_a.find do |action|
    action.method == method && action.path.match(path) && action.content_type == content_type
  end
end
prefix_match?(raw_path) click to toggle source
# File lib/tomograph/tomogram.rb, line 56
def prefix_match?(raw_path)
  raw_path.include?(@prefix)
end
to_a() click to toggle source
# File lib/tomograph/tomogram.rb, line 28
def to_a
  @actions ||= @documentation.to_tomogram
end
to_json() click to toggle source
# File lib/tomograph/tomogram.rb, line 32
def to_json
  JSON.pretty_generate(to_a.map(&:to_hash))
end
to_resources() click to toggle source
# File lib/tomograph/tomogram.rb, line 52
def to_resources
  @resources ||= @documentation.to_resources
end