Class: JsFromRoutes::Route
- Inherits:
-
Object
- Object
- JsFromRoutes::Route
- Defined in:
- lib/js_from_routes/generator.rb
Overview
Internal: A presenter for an individual Rails action.
Instance Method Summary collapse
-
#export ⇒ Object
Public: The ‘export` setting specified for the action.
-
#helper ⇒ Object
Public: The name of the JS helper for the action.
-
#initialize(route, mappings:, controller:, index: 0) ⇒ Route
constructor
A new instance of Route.
-
#inspect ⇒ Object
Internal: Useful as a cache key for the route, and for debugging purposes.
-
#path ⇒ Object
Public: The path for the action.
-
#verb ⇒ Object
Public: The HTTP verb for the action.
Constructor Details
#initialize(route, mappings:, controller:, index: 0) ⇒ Route
Returns a new instance of Route.
61 62 63 |
# File 'lib/js_from_routes/generator.rb', line 61 def initialize(route, mappings:, controller:, index: 0) @route, @mappings, @controller, @index = route, mappings, controller, index end |
Instance Method Details
#export ⇒ Object
Public: The ‘export` setting specified for the action.
66 67 68 |
# File 'lib/js_from_routes/generator.rb', line 66 def export @route.defaults[:export] end |
#helper ⇒ Object
Public: The name of the JS helper for the action. Example: ‘destroyAll’
81 82 83 84 85 86 87 88 |
# File 'lib/js_from_routes/generator.rb', line 81 def helper action = @route.requirements.fetch(:action) if @index > 0 action = @route.name&.sub(@controller.tr(":/", "_"), "") || "#{action}#{verb.titleize}" end helper = action.camelize(:lower) @mappings.fetch(helper, helper) end |
#inspect ⇒ Object
Internal: Useful as a cache key for the route, and for debugging purposes.
91 92 93 |
# File 'lib/js_from_routes/generator.rb', line 91 def inspect "#{verb} #{helper} #{path}" end |
#path ⇒ Object
Public: The path for the action. Example: ‘/users/:id/edit’
76 77 78 |
# File 'lib/js_from_routes/generator.rb', line 76 def path @route.path.spec.to_s.chomp("(.:format)") end |
#verb ⇒ Object
Public: The HTTP verb for the action. Example: ‘patch’
71 72 73 |
# File 'lib/js_from_routes/generator.rb', line 71 def verb @route.verb.split("|").last.downcase end |