class APIBlueprint::OutputPrinter

Prints API blueprint output

Attributes

configuration[RW]
examples[RW]
output[RW]

Public Class Methods

new(configuration, output_collector, output) click to toggle source
# File lib/api_blueprint/output_printer.rb, line 8
def initialize(configuration, output_collector, output)
  @configuration = configuration
  @output_collector = output_collector
  @output = output
end

Public Instance Methods

print() click to toggle source

Private Instance Methods

indent_lines(number_of_spaces, string) click to toggle source
# File lib/api_blueprint/output_printer.rb, line 114
def indent_lines(number_of_spaces, string)
  string
    .split("\n")
    .map { |a| a.prepend(' ' * number_of_spaces) }
    .join("\n")
end
print_action(action_name, action_meta_data) click to toggle source
print_example(example_description, example_metadata) click to toggle source
print_request(example_description, example_metadata) click to toggle source
print_resource(resource_name, actions) click to toggle source
print_resource_group(resource_group_name, resource_group_resources) click to toggle source
print_resource_parameters(resource_name) click to toggle source
print_response(example_metadata) click to toggle source
print_source(example_metadata) click to toggle source
sorted_examples() click to toggle source
# File lib/api_blueprint/output_printer.rb, line 27
def sorted_examples
  @output_collector.resources.sort_by { |k, _v| k }
end
validate_http_verbs(actions, resource_name) click to toggle source
# File lib/api_blueprint/output_printer.rb, line 43
def validate_http_verbs(actions, resource_name)
  http_verbs = actions.keys.map do |action|
    action.scan(/\[([A-Z]+)\]/).flatten[0]
  end

  return if http_verbs.length == http_verbs.uniq.length

  raise "Action HTTP verbs are not unique #{actions.keys.inspect} for "\
        "resource: '#{resource_name}'"
end
validate_resource_name(resource_name) click to toggle source
# File lib/api_blueprint/output_printer.rb, line 54
def validate_resource_name(resource_name)
  return if resource_name =~ %r{^[^\[\]]*\[/[^\]]+\]}

  raise "resource: '#{resource_name}' is invalid. :resource needs to be "\
      'specified according to https://github.com/apiaryio/api-blueprint/blob/master/API%20Blueprint%20Specification.md#resource-section'
end