Class: JsRoutes::Route
- Inherits:
-
Object
- Object
- JsRoutes::Route
- Extended by:
- T::Sig
- Includes:
- Types
- Defined in:
- lib/js_routes/route.rb
Overview
:nodoc:
Constant Summary collapse
- FILTERED_DEFAULT_PARTS =
T.let([:controller, :action].freeze, SymbolArray)
- URL_OPTIONS =
T.let([:protocol, :domain, :host, :port, :subdomain].freeze, SymbolArray)
- NODE_TYPES =
T.let({ GROUP: 1, CAT: 2, SYMBOL: 3, OR: 4, STAR: 5, LITERAL: 6, SLASH: 7, DOT: 8 }.freeze, T::Hash[Symbol, Integer])
Constants included from Types
Types::Application, Types::ApplicationCaller, Types::BannerCaller, Types::Clusivity, Types::ConfigurationBlock, Types::FileName, Types::JourneyRoute, Types::Literal, Types::Options, Types::Prefix, Types::RouteSpec, Types::SpecNode, Types::StringArray, Types::StringHash, Types::SymbolArray, Types::UntypedArray
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.
34 35 36 37 38 |
# File 'lib/js_routes/route.rb', line 34 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.
25 26 27 |
# File 'lib/js_routes/route.rb', line 25 def configuration @configuration end |
#parent_route ⇒ Object (readonly)
Returns the value of attribute parent_route.
31 32 33 |
# File 'lib/js_routes/route.rb', line 31 def parent_route @parent_route end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
28 29 30 |
# File 'lib/js_routes/route.rb', line 28 def route @route end |
Instance Method Details
#body(absolute) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/js_routes/route.rb', line 54 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-sidyeeffects pure_comment = @configuration.esm? ? '/*#__PURE__*/ ' : '' "#{pure_comment}__jsr.r(#{arguments(absolute).map{|a| json(a)}.join(', ')})" end end |
#definition_body ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/js_routes/route.rb', line 67 def definition_body = optional_parts_type ? "#{optional_parts_type} & RouteOptions" : "RouteOptions" predicate = @configuration.optional_definition_params ? '?' : '' args = required_parts.map{|p| "#{apply_case(p)}#{predicate}: RequiredRouteParameter"} args << "options?: #{}" "((\n#{args.join(",\n").indent(2)}\n) => string) & RouteHelperExtras" end |
#helper_types ⇒ Object
48 49 50 51 |
# File 'lib/js_routes/route.rb', line 48 def helper_types return [] unless match_configuration? @configuration.url_links ? [true, false] : [false] end |
#helpers ⇒ Object
41 42 43 44 45 |
# File 'lib/js_routes/route.rb', line 41 def helpers helper_types.map do |absolute| [ documentation, helper_name(absolute), body(absolute) ] end end |
#optional_parts_type ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/js_routes/route.rb', line 76 def optional_parts_type return nil if optional_parts.empty? @optional_parts_type ||= T.let( "{" + optional_parts.map {|p| "#{p}?: OptionalRouteParameter"}.join(', ') + "}", T.nilable(String) ) end |