Class: Locomotive::Misc::ApiDocumentation::Parser
- Inherits:
-
Object
- Object
- Locomotive::Misc::ApiDocumentation::Parser
- Defined in:
- lib/locomotive/misc/api_documentation.rb
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Object
Take all the routes and build the set of RESTFUL resources.
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
31 32 33 |
# File 'lib/locomotive/misc/api_documentation.rb', line 31 def initialize @resources = [] end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
29 30 31 |
# File 'lib/locomotive/misc/api_documentation.rb', line 29 def resources @resources end |
Instance Method Details
#parse ⇒ Object
Take all the routes and build the set of RESTFUL resources
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/locomotive/misc/api_documentation.rb', line 37 def parse routes = Rails.application.routes.routes.each do |route| next unless route.path.spec.to_s =~ %r{^/locomotive/api/} name = route.defaults[:controller].split('/').last resource = resources.find { |r| r[:name] == name } controller = "#{route.defaults[:controller]}_controller".camelize.constantize action = route.defaults[:action].to_sym verb = route.verb.inspect.gsub("\/^", '').gsub("$\/", '') if resource.nil? resource = controller.description resource[:name] = name self.resources << resource end resource[:actions][action] ||= {} resource[:actions][action].merge!(path: route.path.spec.to_s, verb: verb) self.sanitize_params(resource[:actions][action]) end self.resources end |