Sha256: 67b0da8dac1f0fdb540bd5c97c8615db235f07be1c18314bea04613cfc4a4fd9

Contents?: true

Size: 725 Bytes

Versions: 1

Compression:

Stored size: 725 Bytes

Contents

# frozen_string_literal: true

require_relative 'prettier/version'
require_relative 'prettier/objects/route'
require_relative 'prettier/formatter'
require 'rails'

module Rails
  module Routes
    module Prettier
      class << self
        SEARCHABLE_FIELDS = %i[name verb path req_options controller action].freeze

        def all
          ActionDispatch::Routing::RoutesInspector.new(::Rails.application.routes.routes).format(
            Rails::Routes::Prettier::Formatter.new, {}
          )
        end

        SEARCHABLE_FIELDS.each do |field|
          define_method :"find_by_#{field}" do |value|
            all.select { |route| route.send(field) == value }
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails-routes-prettier-1.0.0 lib/rails/routes/prettier.rb