class JsFromRoutes::ControllerRoutes
Internal: Helper class used as a presenter for the routes template.
Attributes
routes[R]
Public Class Methods
new(controller, routes, config)
click to toggle source
# File lib/js_from_routes/generator.rb, line 15 def initialize(controller, routes, config) @controller, @config = controller, config @routes = routes .uniq { |route| route.requirements.fetch(:action) } .map { |route| Route.new(route, config.helper_mappings) } end
Public Instance Methods
basename()
click to toggle source
Internal: The base name of the JS file to be written.
# File lib/js_from_routes/generator.rb, line 49 def basename "#{@controller.camelize}#{@config.file_suffix}".tr_s(":", "/") end
cache_key()
click to toggle source
Public: Used to check whether the file should be generated again, changes based on the configuration, and route definition.
# File lib/js_from_routes/generator.rb, line 24 def cache_key routes.map(&:inspect).join + [File.read(@config.template_path), @config.helper_mappings.inspect, @config.client_library].join end
client_library()
click to toggle source
Public: Exposes the preferred import library to the generator.
# File lib/js_from_routes/generator.rb, line 29 def client_library @config.client_library end
filename()
click to toggle source
Internal: Name of the JS file with helpers for the the given controller.
# File lib/js_from_routes/generator.rb, line 34 def filename @config.output_folder.join(basename) end
import_filename()
click to toggle source
Public: Name of the JS file with helpers for the the given controller.
# File lib/js_from_routes/generator.rb, line 39 def import_filename @config.output_folder.basename.join((basename.split(".")[0]).to_s) end
js_name()
click to toggle source
Public: Name of the file as a valid JS variable.
# File lib/js_from_routes/generator.rb, line 44 def js_name @controller.camelize(:lower).tr(":", "") end