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



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

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

Instance Method Details

#exportObject

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



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

def export
  @route.defaults[:export]
end

#helperObject

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



98
99
100
101
# File 'lib/js_from_routes/generator.rb', line 98

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.



104
105
106
# File 'lib/js_from_routes/generator.rb', line 104

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

#pathObject

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



93
94
95
# File 'lib/js_from_routes/generator.rb', line 93

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

#verbObject

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



88
89
90
# File 'lib/js_from_routes/generator.rb', line 88

def verb
  @route.verb.downcase
end