Class: GrapeApiary::Route
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- GrapeApiary::Route
- Defined in:
- lib/grape-apiary/route.rb
Instance Method Summary collapse
- #description ⇒ Object
- #list? ⇒ Boolean
- #params ⇒ Object
- #path_without_format ⇒ Object
- #request_description ⇒ Object
- #response_description ⇒ Object
- #route_model ⇒ Object
- #route_name ⇒ Object
- #route_type ⇒ Object
Instance Method Details
#description ⇒ Object
20 21 22 |
# File 'lib/grape-apiary/route.rb', line 20 def description "#{__getobj__.description} [#{request_method.upcase}]" end |
#list? ⇒ Boolean
46 47 48 |
# File 'lib/grape-apiary/route.rb', line 46 def list? %w(GET POST).include?(request_method) && !path.include?(':id') end |
#params ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/grape-apiary/route.rb', line 7 def params @params ||= begin __getobj__.params.stringify_keys.sort.map do |param| Parameter.new(self, *param) end end end |
#path_without_format ⇒ Object
24 25 26 |
# File 'lib/grape-apiary/route.rb', line 24 def path_without_format path.gsub(/\((.*?)\)/, '') end |
#request_description ⇒ Object
36 37 38 |
# File 'lib/grape-apiary/route.rb', line 36 def request_description "+ Request #{'(application/json)' if request_body?}" end |
#response_description ⇒ Object
40 41 42 43 44 |
# File 'lib/grape-apiary/route.rb', line 40 def response_description code = request_method == 'POST' ? 201 : 200 "+ Response #{code} (application/json)" end |
#route_model ⇒ Object
28 29 30 |
# File 'lib/grape-apiary/route.rb', line 28 def route_model namespace.split('/').last.singularize end |
#route_name ⇒ Object
15 16 17 18 |
# File 'lib/grape-apiary/route.rb', line 15 def route_name namespace.split('/').last || path.match('\/(\w*?)[\.\/\(]').captures.first end |
#route_type ⇒ Object
32 33 34 |
# File 'lib/grape-apiary/route.rb', line 32 def route_type list? ? 'collection' : 'single' end |