Class: JsFromRoutes::ControllerRoutes
- Inherits:
-
Object
- Object
- JsFromRoutes::ControllerRoutes
- Defined in:
- lib/js_from_routes/generator.rb
Overview
Internal: Helper class used as a presenter for the routes template.
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#basename ⇒ Object
Internal: The base name of the JS file to be written.
-
#cache_key ⇒ Object
Public: Used to check whether the file should be generated again, changes based on the configuration, and route definition.
-
#client_library ⇒ Object
Public: Exposes the preferred import library to the generator.
-
#filename ⇒ Object
Internal: Name of the JS file with helpers for the the given controller.
-
#import_filename ⇒ Object
Public: Name of the JS file with helpers for the the given controller.
-
#initialize(controller, routes, config) ⇒ ControllerRoutes
constructor
A new instance of ControllerRoutes.
-
#js_name ⇒ Object
Public: Name of the file as a valid JS variable.
Constructor Details
#initialize(controller, routes, config) ⇒ ControllerRoutes
Returns a new instance of ControllerRoutes.
37 38 39 40 41 42 |
# File 'lib/js_from_routes/generator.rb', line 37 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 |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
35 36 37 |
# File 'lib/js_from_routes/generator.rb', line 35 def routes @routes end |
Instance Method Details
#basename ⇒ Object
Internal: The base name of the JS file to be written.
71 72 73 |
# File 'lib/js_from_routes/generator.rb', line 71 def basename "#{@controller.camelize}#{@config.file_suffix}".tr_s(":", "/") end |
#cache_key ⇒ Object
Public: Used to check whether the file should be generated again, changes based on the configuration, and route definition.
46 47 48 |
# File 'lib/js_from_routes/generator.rb', line 46 def cache_key routes.map(&:inspect).join + [File.read(@config.template_path), @config.helper_mappings.inspect, @config.client_library].join end |
#client_library ⇒ Object
Public: Exposes the preferred import library to the generator.
51 52 53 |
# File 'lib/js_from_routes/generator.rb', line 51 def client_library @config.client_library end |
#filename ⇒ Object
Internal: Name of the JS file with helpers for the the given controller.
56 57 58 |
# File 'lib/js_from_routes/generator.rb', line 56 def filename @config.output_folder.join(basename) end |
#import_filename ⇒ Object
Public: Name of the JS file with helpers for the the given controller.
61 62 63 |
# File 'lib/js_from_routes/generator.rb', line 61 def import_filename @config.output_folder.basename.join((basename.split(".")[0]).to_s) end |
#js_name ⇒ Object
Public: Name of the file as a valid JS variable.
66 67 68 |
# File 'lib/js_from_routes/generator.rb', line 66 def js_name @controller.camelize(:lower).tr(":", "") end |