Class: JsFromRoutes::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/js_from_routes/generator.rb

Overview

Internal: A presenter for an individual Rails action.

Instance Method Summary collapse

Constructor Details

#initialize(route, mappings = {}) ⇒ Route

Returns a new instance of Route.



56
57
58
# File 'lib/js_from_routes/generator.rb', line 56

def initialize(route, mappings = {})
  @route, @mappings = route, mappings
end

Instance Method Details

#exportObject

Public: The ‘export` setting specified for the action.



61
62
63
# File 'lib/js_from_routes/generator.rb', line 61

def export
  @route.defaults[:export]
end

#helperObject

Public: The name of the JS helper for the action. Example: ‘destroyAll’



76
77
78
79
# File 'lib/js_from_routes/generator.rb', line 76

def helper
  action = @route.requirements.fetch(:action).camelize(:lower)
  @mappings.fetch(action, action)
end

#inspectObject

Internal: Useful as a cache key for the route, and for debugging purposes.



82
83
84
# File 'lib/js_from_routes/generator.rb', line 82

def inspect
  "#{verb} #{helper} #{path}"
end

#pathObject

Public: The path for the action. Example: ‘/users/:id/edit’



71
72
73
# File 'lib/js_from_routes/generator.rb', line 71

def path
  @route.path.spec.to_s.chomp("(.:format)")
end

#verbObject

Public: The HTTP verb for the action. Example: ‘patch’



66
67
68
# File 'lib/js_from_routes/generator.rb', line 66

def verb
  @route.verb.downcase
end