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.
46 47 48 |
# File 'lib/locomotive/misc/api_documentation.rb', line 46 def initialize @resources = [] end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
44 45 46 |
# File 'lib/locomotive/misc/api_documentation.rb', line 44 def resources @resources end |
Instance Method Details
#parse ⇒ Object
Take all the routes and build the set of RESTFUL resources
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/locomotive/misc/api_documentation.rb', line 52 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("$\/", '') next if name == 'documentation' 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_attributes(resource[:actions][action]) end self.resources end |