class GrapeApiary::Blueprint
Attributes
api_class[R]
blueprint_template[R]
properties_template[R]
Public Class Methods
new(api_class)
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 7 def initialize(api_class) @api_class = api_class @blueprint_template = template_for(:blueprint) @properties_template = template_for(:properties) end
Public Instance Methods
formatted_request_headers()
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 41 def formatted_request_headers formatted_headers(GrapeApiary::Config.request_headers) end
formatted_response_headers()
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 45 def formatted_response_headers formatted_headers(GrapeApiary::Config.response_headers) end
generate()
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 13 def generate ERB.new(blueprint_template, nil, '-').result(binding) end
properties_table(resource)
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 37 def properties_table(resource) ERB.new(properties_template, nil, '-').result(resource.resource_binding) end
resources()
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 27 def resources @resources ||= begin grouped_routes = routes.group_by(&:route_name).reject do |name, _| resource_exclusion.include?(name.to_sym) end grouped_routes.map { |name, routes| Resource.new(name, routes) } end end
routes()
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 21 def routes @routes ||= api_class.routes.map do |route| GrapeApiary::Route.new(route) end end
show_request_sample?(route)
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 49 def show_request_sample?(route) %w(PUT POST).include?(route.request_method) end
write()
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 17 def write raise 'Not yet supported' end
Private Instance Methods
formatted_headers(headers)
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 62 def formatted_headers(headers) return '' unless headers.present? spacer = "\n" + (' ' * 12) strings = headers.map do |header| key, value = *header.first "#{key}: #{value}" end " + Headers\n" + spacer + strings.join(spacer) end
template_for(name)
click to toggle source
# File lib/grape-apiary/blueprint.rb, line 55 def template_for(name) directory = File.dirname(File.expand_path(__FILE__)) path = File.join(directory, "./templates/#{name}.md.erb") File.read(path) end