Class: JsRoutes::Configuration

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil) ⇒ Configuration

Returns a new instance of Configuration.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/js_routes/configuration.rb', line 59

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)
  @include_undefined_query_parameters = T.let(nil, T.nilable(T::Boolean))
  @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(default_banner, BannerCaller)
  @package = T.let(nil, T.nilable(String))
  @deprecated_false_parameter_behavior = T.let(
    defined?(Rails) ? JsRoutes::Utils.rails_version < Gem::Version.new('7.0.0') : false,
    T::Boolean
  )
  @deprecated_nil_query_parameter_behavior = T.let(
    defined?(Rails) ? JsRoutes::Utils.rails_version < Gem::Version.new('8.1.0') : false,
    T::Boolean
  )

  return unless attributes
  assign(attributes)
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



44
45
46
# File 'lib/js_routes/configuration.rb', line 44

def application
  @application
end

Returns the value of attribute banner.



52
53
54
# File 'lib/js_routes/configuration.rb', line 52

def banner
  @banner
end

#camel_caseObject

Returns the value of attribute camel_case.



32
33
34
# File 'lib/js_routes/configuration.rb', line 32

def camel_case
  @camel_case
end

#compactObject

Returns the value of attribute compact.



38
39
40
# File 'lib/js_routes/configuration.rb', line 38

def compact
  @compact
end

#default_url_optionsObject

Returns the value of attribute default_url_options.



34
35
36
# File 'lib/js_routes/configuration.rb', line 34

def default_url_options
  @default_url_options
end

#deprecated_false_parameter_behaviorObject

Returns the value of attribute deprecated_false_parameter_behavior.



54
55
56
# File 'lib/js_routes/configuration.rb', line 54

def deprecated_false_parameter_behavior
  @deprecated_false_parameter_behavior
end

#deprecated_nil_query_parameter_behaviorObject

Returns the value of attribute deprecated_nil_query_parameter_behavior.



56
57
58
# File 'lib/js_routes/configuration.rb', line 56

def deprecated_nil_query_parameter_behavior
  @deprecated_nil_query_parameter_behavior
end

#documentationObject

Returns the value of attribute documentation.



46
47
48
# File 'lib/js_routes/configuration.rb', line 46

def documentation
  @documentation
end

#excludeObject

Returns the value of attribute exclude.



16
17
18
# File 'lib/js_routes/configuration.rb', line 16

def exclude
  @exclude
end

#fileObject

Returns the value of attribute file.



20
21
22
# File 'lib/js_routes/configuration.rb', line 20

def file
  @file
end

#includeObject

Returns the value of attribute include.



18
19
20
# File 'lib/js_routes/configuration.rb', line 18

def include
  @include
end

#include_undefined_query_parametersObject

Returns the value of attribute include_undefined_query_parameters.



36
37
38
# File 'lib/js_routes/configuration.rb', line 36

def include_undefined_query_parameters
  @include_undefined_query_parameters
end

#module_typeObject

Returns the value of attribute module_type.



48
49
50
# File 'lib/js_routes/configuration.rb', line 48

def module_type
  @module_type
end

#namespaceObject

Returns the value of attribute namespace.



14
15
16
# File 'lib/js_routes/configuration.rb', line 14

def namespace
  @namespace
end

#optional_definition_paramsObject

Returns the value of attribute optional_definition_params.



50
51
52
# File 'lib/js_routes/configuration.rb', line 50

def optional_definition_params
  @optional_definition_params
end

#packageObject

Returns the value of attribute package.



22
23
24
# File 'lib/js_routes/configuration.rb', line 22

def package
  @package
end

#prefixObject

Returns the value of attribute prefix.



28
29
30
# File 'lib/js_routes/configuration.rb', line 28

def prefix
  @prefix
end

#serializerObject

Returns the value of attribute serializer.



40
41
42
# File 'lib/js_routes/configuration.rb', line 40

def serializer
  @serializer
end

#special_options_keyObject

Returns the value of attribute special_options_key.



42
43
44
# File 'lib/js_routes/configuration.rb', line 42

def special_options_key
  @special_options_key
end

Returns the value of attribute url_links.



30
31
32
# File 'lib/js_routes/configuration.rb', line 30

def url_links
  @url_links
end

Class Method Details

.rails_javascript_pathObject



186
187
188
189
190
191
192
193
# File 'lib/js_routes/configuration.rb', line 186

def self.rails_javascript_path
  js_dir = if defined?(Rails) && Rails.application&.config&.respond_to?(:javascript_path)
    Rails.application.config.javascript_path
  else
    "javascript"
  end
  "app/#{js_dir}"
end

Instance Method Details

#[](attribute) ⇒ Object



112
113
114
# File 'lib/js_routes/configuration.rb', line 112

def [](attribute)
  public_send(attribute)
end

#assign(attributes) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/js_routes/configuration.rb', line 96

def assign(attributes)
  if attributes
    attributes.each do |attribute, value|
      public_send(:"#{attribute}=", value)
    end
  end
  normalize_and_verify
  self
end

#dts?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/js_routes/configuration.rb', line 132

def dts?
  self.module_type === 'DTS'
end

#esm?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/js_routes/configuration.rb', line 127

def esm?
  module_type === 'ESM'
end

#merge(attributes) ⇒ Object



122
123
124
# File 'lib/js_routes/configuration.rb', line 122

def merge(attributes)
  clone.assign(attributes)
end

#modern?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/js_routes/configuration.rb', line 142

def modern?
  esm? || dts?
end

#output_fileObject



168
169
170
# File 'lib/js_routes/configuration.rb', line 168

def output_file
  output_file_path(file || default_file_name)
end

#pkg?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/js_routes/configuration.rb', line 137

def pkg?
  module_type === 'PKG'
end

#require_esmObject



151
152
153
# File 'lib/js_routes/configuration.rb', line 151

def require_esm
  raise "ESM module type is required" unless modern?
end

#router_source_fileObject



162
163
164
165
# File 'lib/js_routes/configuration.rb', line 162

def router_source_file
  template = dts? ? "router.d.ts" : "router.js"
  File.dirname(__FILE__) + "/../" + template
end

#setup(&block) ⇒ Object



107
108
109
# File 'lib/js_routes/configuration.rb', line 107

def setup(&block)
  tap(&block)
end

#source_fileObject



156
157
158
159
# File 'lib/js_routes/configuration.rb', line 156

def source_file
  template = dts? ? "routes.d.ts" : "routes.js"
  File.dirname(__FILE__) + "/../" + template
end

#use_package?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/js_routes/configuration.rb', line 146

def use_package?
  esm? && package
end