Class: JsRoutes::Route
- Inherits:
-
Object
- Object
- JsRoutes::Route
- Defined in:
- lib/js_routes/route.rb
Overview
:nodoc:
Constant Summary collapse
- FILTERED_DEFAULT_PARTS =
[:controller, :action]
- URL_OPTIONS =
[:protocol, :domain, :host, :port, :subdomain]
- NODE_TYPES =
{ GROUP: 1, CAT: 2, SYMBOL: 3, OR: 4, STAR: 5, LITERAL: 6, SLASH: 7, DOT: 8 }
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#parent_route ⇒ Object
readonly
Returns the value of attribute parent_route.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #body(absolute) ⇒ Object
- #definition_body ⇒ Object
- #helper_types ⇒ Object
- #helpers ⇒ Object
-
#initialize(configuration, route, parent_route = nil) ⇒ Route
constructor
A new instance of Route.
- #optional_parts_type ⇒ Object
Constructor Details
#initialize(configuration, route, parent_route = nil) ⇒ Route
Returns a new instance of Route.
18 19 20 21 22 |
# File 'lib/js_routes/route.rb', line 18 def initialize(configuration, route, parent_route = nil) @configuration = configuration @route = route @parent_route = parent_route end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
16 17 18 |
# File 'lib/js_routes/route.rb', line 16 def configuration @configuration end |
#parent_route ⇒ Object (readonly)
Returns the value of attribute parent_route.
16 17 18 |
# File 'lib/js_routes/route.rb', line 16 def parent_route @parent_route end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
16 17 18 |
# File 'lib/js_routes/route.rb', line 16 def route @route end |
Instance Method Details
#body(absolute) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/js_routes/route.rb', line 35 def body(absolute) if @configuration.dts? definition_body else # For tree-shaking ESM, add a #__PURE__ comment informing Webpack/minifiers that the call to `__jsr.r` # has no side-effects (e.g. modifying global variables) and is safe to remove when unused. # https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects pure_comment = @configuration.esm? ? '/*#__PURE__*/ ' : '' "#{pure_comment}__jsr.r(#{arguments(absolute).map{|a| json(a)}.join(', ')})" end end |
#definition_body ⇒ Object
47 48 49 50 51 |
# File 'lib/js_routes/route.rb', line 47 def definition_body args = required_parts.map{|p| "#{apply_case(p)}: RequiredRouteParameter"} args << "options?: #{optional_parts_type} & RouteOptions" "((\n#{args.join(",\n").indent(2)}\n) => string) & RouteHelperExtras" end |
#helper_types ⇒ Object
30 31 32 33 |
# File 'lib/js_routes/route.rb', line 30 def helper_types return [] unless match_configuration? @configuration[:url_links] ? [true, false] : [false] end |
#helpers ⇒ Object
24 25 26 27 28 |
# File 'lib/js_routes/route.rb', line 24 def helpers helper_types.map do |absolute| [ documentation, helper_name(absolute), body(absolute) ] end end |
#optional_parts_type ⇒ Object
53 54 55 56 |
# File 'lib/js_routes/route.rb', line 53 def optional_parts_type @optional_parts_type ||= "{" + optional_parts.map {|p| "#{p}?: OptionalRouteParameter"}.join(', ') + "}" end |