class GrapeMarkdown::Resource

Attributes

key[R]
name[R]
routes[R]
sample_generator[R]

Public Class Methods

new(key, routes) click to toggle source
# File lib/grape-markdown/resource.rb, line 5
def initialize(key, routes)
  @key              = key
  @name             = key.humanize
  @routes           = routes
  @sample_generator = SampleGenerator.new(self)
end

Public Instance Methods

header() click to toggle source
# File lib/grape-markdown/resource.rb, line 28
def header
  # TODO: ???
  route = routes.first

  "#{title} #{route.route_type} [#{route.route_path_without_format}]"
end
namespaced() click to toggle source
# File lib/grape-markdown/resource.rb, line 16
def namespaced
  @namespaced ||= routes.group_by(&:namespace).map do |_, routes|
    Resource.new(name, routes)
  end
end
paths() click to toggle source
# File lib/grape-markdown/resource.rb, line 22
def paths
  @paths ||= routes.group_by(&:route_path_without_format).map do |_, routes|
    Resource.new(name, routes)
  end
end
resource_binding() click to toggle source
# File lib/grape-markdown/resource.rb, line 59
def resource_binding
  binding
end
sample_request(pretty = true) click to toggle source
# File lib/grape-markdown/resource.rb, line 35
def sample_request(pretty = true)
  sample_generator.request(pretty: pretty)
end
sample_response(route, pretty = true) click to toggle source
# File lib/grape-markdown/resource.rb, line 39
def sample_response(route, pretty = true)
  sample_generator.response(list: route.list?, pretty: pretty)
end
title() click to toggle source
# File lib/grape-markdown/resource.rb, line 12
def title
  @title ||= name.titleize
end
unique_params() click to toggle source
# File lib/grape-markdown/resource.rb, line 43
def unique_params
  # TODO: this is a hack, assuming that the resource has a POST or PUT
  # route that defines all of the parameters that would define the resource
  methods = %w(POST PUT)

  potential = routes.select do |route|
    methods.include?(route.request_method) && route.route_params.present?
  end

  if potential.present?
    potential.first.route_params
  else
    []
  end
end