Sha256: 639632ec39a9f955f30629e03805058739341943c03f88839fefcf73fdce835a

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

namespace :praxis do

  desc 'List routes, format=json or table, default table'
  task :routes, [:format] => [:environment] do |t, args|
    require 'ruport'

    table = Table(:version, :path, :verb, :resource, 
      :action, :implementation, :name, :primary)

    Praxis::Application.instance.resource_definitions.each do |resource_definition|
      resource_definition.actions.each do |name, action|
        method = begin
          m = resource_definition.controller.instance_method(name)
        rescue
          nil
        end
        
        method_name = method ? "#{method.owner.name}##{method.name}" : 'n/a'

        action.routes.each do |route|
          table << {
            resource: resource_definition.name,
            version: route.version,
            verb: route.verb,
            path: route.path,
            action: name,
            implementation: method_name,
            name: route.name,
            primary: (action.primary_route == route ? 'yes' : '')
          }
        end
      end
    end

    case args[:format] || "table"
    when "json"
      puts JSON.pretty_generate(table.collect { |r| r.to_hash })
    when "table"
      puts table.to_s
    else
      raise "unknown output format: #{args[:format]}"
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
praxis-0.11.2 lib/praxis/tasks/routes.rb
praxis-0.11.1 lib/praxis/tasks/routes.rb
praxis-0.11 lib/praxis/tasks/routes.rb
praxis-0.11pre lib/praxis/tasks/routes.rb
praxis-0.10.1 lib/praxis/tasks/routes.rb
praxis-0.10.0 lib/praxis/tasks/routes.rb
praxis-0.9 lib/praxis/tasks/routes.rb