Class: JsRoutes::Configuration
- Inherits:
-
Object
- Object
- JsRoutes::Configuration
- Extended by:
- T::Sig
- Includes:
- Types
- Defined in:
- lib/js_routes/configuration.rb
Constant Summary
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
-
#application ⇒ Object
Returns the value of attribute application.
-
#banner ⇒ Object
Returns the value of attribute banner.
-
#camel_case ⇒ Object
Returns the value of attribute camel_case.
-
#compact ⇒ Object
Returns the value of attribute compact.
-
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
-
#documentation ⇒ Object
Returns the value of attribute documentation.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#file ⇒ Object
Returns the value of attribute file.
-
#include ⇒ Object
Returns the value of attribute include.
-
#module_type ⇒ Object
Returns the value of attribute module_type.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#optional_definition_params ⇒ Object
Returns the value of attribute optional_definition_params.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#serializer ⇒ Object
Returns the value of attribute serializer.
-
#special_options_key ⇒ Object
Returns the value of attribute special_options_key.
-
#url_links ⇒ Object
Returns the value of attribute url_links.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #assign(attributes) ⇒ Object
- #dts? ⇒ Boolean
- #esm? ⇒ Boolean
-
#initialize(attributes = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #merge(attributes) ⇒ Object
- #modern? ⇒ Boolean
- #output_file ⇒ Object
- #require_esm ⇒ Object
- #setup(&block) ⇒ Object
- #source_file ⇒ Object
Constructor Details
#initialize(attributes = nil) ⇒ Configuration
Returns a new instance of Configuration.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/js_routes/configuration.rb', line 47 def initialize(attributes = nil) @namespace = nil @exclude = T.let([], Clusivity) @include = T.let([//], Clusivity) @file = T.let(nil, FileName) @prefix = T.let(-> { Rails.application.config.relative_url_root || "" }, T.untyped) @url_links = T.let(false, T::Boolean) @camel_case = T.let(false, T::Boolean) @default_url_options = T.let(T.unsafe({}), Options) @compact = T.let(false, T::Boolean) @serializer = T.let(nil, T.nilable(String)) @special_options_key = T.let("_options", Literal) @application = T.let(T.unsafe(-> { Rails.application }), ApplicationCaller) @module_type = T.let('ESM', T.nilable(String)) @documentation = T.let(true, T::Boolean) @optional_definition_params = T.let(false, T::Boolean) @banner = T.let(, BannerCaller) return unless attributes assign(attributes) end |
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
36 37 38 |
# File 'lib/js_routes/configuration.rb', line 36 def application @application end |
#banner ⇒ Object
Returns the value of attribute banner.
44 45 46 |
# File 'lib/js_routes/configuration.rb', line 44 def @banner end |
#camel_case ⇒ Object
Returns the value of attribute camel_case.
26 27 28 |
# File 'lib/js_routes/configuration.rb', line 26 def camel_case @camel_case end |
#compact ⇒ Object
Returns the value of attribute compact.
30 31 32 |
# File 'lib/js_routes/configuration.rb', line 30 def compact @compact end |
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
28 29 30 |
# File 'lib/js_routes/configuration.rb', line 28 def @default_url_options end |
#documentation ⇒ Object
Returns the value of attribute documentation.
38 39 40 |
# File 'lib/js_routes/configuration.rb', line 38 def documentation @documentation end |
#exclude ⇒ Object
Returns the value of attribute exclude.
16 17 18 |
# File 'lib/js_routes/configuration.rb', line 16 def exclude @exclude end |
#file ⇒ Object
Returns the value of attribute file.
20 21 22 |
# File 'lib/js_routes/configuration.rb', line 20 def file @file end |
#include ⇒ Object
Returns the value of attribute include.
18 19 20 |
# File 'lib/js_routes/configuration.rb', line 18 def include @include end |
#module_type ⇒ Object
Returns the value of attribute module_type.
40 41 42 |
# File 'lib/js_routes/configuration.rb', line 40 def module_type @module_type end |
#namespace ⇒ Object
Returns the value of attribute namespace.
14 15 16 |
# File 'lib/js_routes/configuration.rb', line 14 def namespace @namespace end |
#optional_definition_params ⇒ Object
Returns the value of attribute optional_definition_params.
42 43 44 |
# File 'lib/js_routes/configuration.rb', line 42 def optional_definition_params @optional_definition_params end |
#prefix ⇒ Object
Returns the value of attribute prefix.
22 23 24 |
# File 'lib/js_routes/configuration.rb', line 22 def prefix @prefix end |
#serializer ⇒ Object
Returns the value of attribute serializer.
32 33 34 |
# File 'lib/js_routes/configuration.rb', line 32 def serializer @serializer end |
#special_options_key ⇒ Object
Returns the value of attribute special_options_key.
34 35 36 |
# File 'lib/js_routes/configuration.rb', line 34 def @special_options_key end |
#url_links ⇒ Object
Returns the value of attribute url_links.
24 25 26 |
# File 'lib/js_routes/configuration.rb', line 24 def url_links @url_links end |
Instance Method Details
#[](attribute) ⇒ Object
90 91 92 |
# File 'lib/js_routes/configuration.rb', line 90 def [](attribute) public_send(attribute) end |
#assign(attributes) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/js_routes/configuration.rb', line 74 def assign(attributes) if attributes attributes.each do |attribute, value| public_send(:"#{attribute}=", value) end end normalize_and_verify self end |
#dts? ⇒ Boolean
110 111 112 |
# File 'lib/js_routes/configuration.rb', line 110 def dts? self.module_type === 'DTS' end |
#esm? ⇒ Boolean
105 106 107 |
# File 'lib/js_routes/configuration.rb', line 105 def esm? module_type === 'ESM' end |
#merge(attributes) ⇒ Object
100 101 102 |
# File 'lib/js_routes/configuration.rb', line 100 def merge(attributes) clone.assign(attributes) end |
#modern? ⇒ Boolean
115 116 117 |
# File 'lib/js_routes/configuration.rb', line 115 def modern? esm? || dts? end |
#output_file ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/js_routes/configuration.rb', line 130 def output_file shakapacker = JsRoutes::Utils.shakapacker shakapacker_dir = shakapacker ? shakapacker.config.source_path : pathname('app', 'javascript') sprockets_dir = pathname('app','assets','javascripts') file_name = file || default_file_name sprockets_file = sprockets_dir.join(file_name) webpacker_file = shakapacker_dir.join(file_name) !Dir.exist?(shakapacker_dir) && defined?(::Sprockets) ? sprockets_file : webpacker_file end |
#require_esm ⇒ Object
120 121 122 |
# File 'lib/js_routes/configuration.rb', line 120 def require_esm raise "ESM module type is required" unless modern? end |
#setup(&block) ⇒ Object
85 86 87 |
# File 'lib/js_routes/configuration.rb', line 85 def setup(&block) tap(&block) end |
#source_file ⇒ Object
125 126 127 |
# File 'lib/js_routes/configuration.rb', line 125 def source_file File.dirname(__FILE__) + "/../" + default_file_name end |