class GrapeApiary::Resource
Attributes
key[R]
name[R]
routes[R]
sample_generator[R]
Public Class Methods
new(key, routes)
click to toggle source
# File lib/grape-apiary/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-apiary/resource.rb, line 28 def header # TODO: ??? route = routes.first "#{title} #{route.route_type} [#{route.path_without_format}]" end
namespaced()
click to toggle source
# File lib/grape-apiary/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-apiary/resource.rb, line 22 def paths @paths ||= routes.group_by(&:path_without_format).map do |_, routes| Resource.new(name, routes) end end
resource_binding()
click to toggle source
# File lib/grape-apiary/resource.rb, line 59 def resource_binding binding end
sample_request()
click to toggle source
# File lib/grape-apiary/resource.rb, line 35 def sample_request sample_generator.request end
sample_response(route)
click to toggle source
# File lib/grape-apiary/resource.rb, line 39 def sample_response(route) sample_generator.response(route.list?) end
title()
click to toggle source
# File lib/grape-apiary/resource.rb, line 12 def title @title ||= name.titleize end
unique_params()
click to toggle source
# File lib/grape-apiary/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.params.present? end if potential.present? potential.first.params else [] end end