lib/locomotive/misc/api_documentation.rb
# Take all the routes and build the set of RESTFUL resources
#
Take all the routes and build the set of RESTFUL resources
Take all the routes and build the set of RESTFUL resources
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
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
Take all the routes and build the set of RESTFUL resources
Take all the routes and build the set of RESTFUL resources