Skip to content

Formatting #5

Description

@pboling

The current formatting is horrible (say it with a Spanish accent, please!).

This is what I have hacked up.

In the style of rails routes... (nicely formatted)

namespace :grape do
  desc "Condensed API Routes"
  task :routes => :environment do
    mapped_prefix = '/whatevs' # where mounted in routes.rb
    format = "%46s  %3s %7s %50s %12s:  %s"
    API.routes.each do |grape_route|
      info = grape_route.instance_variable_get :@options
      puts format % [
        info[:description] ? info[:description][0..45] : '',
        info[:version],
        info[:method],
        mapped_prefix + info[:path],
        '# params: ' + info[:params].length.to_s,
        info[:params].first.inspect
      ]
      if info[:params].length > 1
        info[:params].each_with_index do |param_info, index|
          next if index == 0
          puts format % ['','','','','',param_info.inspect]
        end
      end
    end
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions