Sha256: 9189f8d67cff25d65efa44345ce8634841871db23996fa326606ad2a6c7462cc

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

Contents

require 'pretty_routes/engine'

#
# Base module of pretty routes
#
module PrettyRoutes
  begin
    require 'rails/application/route_inspector'
    ROUTE_INSPECTOR = Rails::Application::RouteInspector.new
  rescue LoadError
    require 'action_dispatch/routing/inspector'
    ROUTE_INSPECTOR = ActionDispatch::Routing::RoutesInspector.new([])
  end

  def self.format_routes(routes = all_routes)
    # Rails routes
    rails_routes = ROUTE_INSPECTOR.send :collect_routes, routes
    # Parse rails routes to find constraints
    rails_routes.each do |route|
      next unless route[:reqs].include?(' {')
      reqs = route[:reqs].split(' ')
      route[:reqs] = reqs.first
      route[:constraints] = reqs.last
    end
    # Return parsed
    rails_routes
  end

  # Reload and return Rails routes.
  #
  def self.all_routes
    Rails.application.reload_routes!
    Rails.application.routes.routes
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pretty_routes-0.2.0 lib/pretty_routes.rb
pretty_routes-0.1.1 lib/pretty_routes.rb
pretty_routes-0.1.0 lib/pretty_routes.rb