Class: Monolith::RoutesController::Route
- Inherits:
-
Object
- Object
- Monolith::RoutesController::Route
- Defined in:
- app/controllers/monolith/routes_controller.rb
Overview
Inline ActiveModel-like object
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#required_parts ⇒ Object
readonly
Returns the value of attribute required_parts.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Class Method Summary collapse
Instance Method Summary collapse
- #display_name ⇒ Object
- #full_controller_action ⇒ Object
-
#initialize(name:, verb:, path:, controller:, action:, constraints:, defaults:, required_parts:, id:) ⇒ Route
constructor
A new instance of Route.
- #to_param ⇒ Object
Constructor Details
#initialize(name:, verb:, path:, controller:, action:, constraints:, defaults:, required_parts:, id:) ⇒ Route
Returns a new instance of Route.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/monolith/routes_controller.rb', line 56 def initialize(name:, verb:, path:, controller:, action:, constraints:, defaults:, required_parts:, id:) @name = name @verb = verb @path = path @controller = controller @action = action @constraints = constraints @defaults = defaults @required_parts = required_parts @id = id end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def action @action end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def constraints @constraints end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def controller @controller end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def defaults @defaults end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def path @path end |
#required_parts ⇒ Object (readonly)
Returns the value of attribute required_parts.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def required_parts @required_parts end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
19 20 21 |
# File 'app/controllers/monolith/routes_controller.rb', line 19 def verb @verb end |
Class Method Details
.all ⇒ Object
21 22 23 |
# File 'app/controllers/monolith/routes_controller.rb', line 21 def self.all Rails.application.routes.routes.map.with_index { |route, idx| from_route(route, idx) }.compact.sort_by(&:display_name) end |
.find(id) ⇒ Object
25 26 27 |
# File 'app/controllers/monolith/routes_controller.rb', line 25 def self.find(id) all.find { |r| r.to_param == id } end |
.from_route(route, idx) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/monolith/routes_controller.rb', line 29 def self.from_route(route, idx) name = route.name.to_s verb = route.verb.to_s path = route.path.spec.to_s # Extract controller and action defaults = route.defaults controller = defaults[:controller] action = defaults[:action] # Skip routes without controller/action or internal Rails routes return nil if controller.nil? || action.nil? return nil if controller.to_s.start_with?("rails/") new( name: name.empty? ? nil : name, verb: verb, path: path, controller: controller, action: action, constraints: route.constraints.except(:request_method), defaults: defaults.except(:controller, :action), required_parts: route.required_parts, id: idx ) end |
Instance Method Details
#display_name ⇒ Object
72 73 74 |
# File 'app/controllers/monolith/routes_controller.rb', line 72 def display_name name || "#{controller}##{action}" end |
#full_controller_action ⇒ Object
76 77 78 |
# File 'app/controllers/monolith/routes_controller.rb', line 76 def full_controller_action "#{controller}##{action}" end |
#to_param ⇒ Object
68 69 70 |
# File 'app/controllers/monolith/routes_controller.rb', line 68 def to_param @id.to_s end |