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_setting ⇒ Object
Public: The ‘export` setting specified for the action.
-
#helper ⇒ Object
Public: The name of the JS helper for the action.
-
#initialize(route, mappings = {}) ⇒ 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.
-
#path_only? ⇒ Boolean
Public: Whether it should export only the path.
-
#request_method? ⇒ Boolean
Public: Whether it should export only the path.
-
#verb ⇒ Object
Public: The HTTP verb for the action.
Constructor Details
#initialize(route, mappings = {}) ⇒ Route
Returns a new instance of Route.
36 37 38 |
# File 'lib/js_from_routes/generator.rb', line 36 def initialize(route, mappings = {}) @route, @mappings = route, mappings end |
Instance Method Details
#export_setting ⇒ Object
Public: The ‘export` setting specified for the action.
46 47 48 |
# File 'lib/js_from_routes/generator.rb', line 46 def export_setting @route.defaults[:export] end |
#helper ⇒ Object
Public: The name of the JS helper for the action. Example: ‘destroyAll’
66 67 68 69 70 |
# File 'lib/js_from_routes/generator.rb', line 66 def helper action = @route.requirements.fetch(:action).camelize(:lower) name = @mappings.fetch(action, action) path_only? ? "#{ name }Path" : name end |
#inspect ⇒ Object
Internal: Useful as a cache key for the route, and for debugging purposes.
73 74 75 |
# File 'lib/js_from_routes/generator.rb', line 73 def inspect "#{ verb } #{ helper } #{ path }" end |
#path ⇒ Object
Public: The path for the action. Example: ‘/users/:id/edit’
61 62 63 |
# File 'lib/js_from_routes/generator.rb', line 61 def path @route.path.spec.to_s.chomp('(.:format)') end |
#path_only? ⇒ Boolean
Public: Whether it should export only the path.
41 42 43 |
# File 'lib/js_from_routes/generator.rb', line 41 def path_only? export_setting == :path_only end |
#request_method? ⇒ Boolean
Public: Whether it should export only the path.
51 52 53 |
# File 'lib/js_from_routes/generator.rb', line 51 def request_method? !path_only? end |
#verb ⇒ Object
Public: The HTTP verb for the action. Example: ‘patch’
56 57 58 |
# File 'lib/js_from_routes/generator.rb', line 56 def verb @route.verb.downcase end |