class JsRoutes::Configuration
Attributes
application[RW]
camel_case[RW]
compact[RW]
default_url_options[RW]
documentation[RW]
exclude[RW]
file[RW]
include[RW]
module_type[RW]
namespace[RW]
prefix[RW]
serializer[RW]
special_options_key[RW]
url_links[RW]
Public Class Methods
new(attributes = nil)
click to toggle source
# File lib/js_routes/configuration.rb, line 42 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(-> { Rails.application }, ApplicationCaller) @module_type = T.let('ESM', T.nilable(String)) @documentation = T.let(true, T::Boolean) return unless attributes assign(attributes) end
Public Instance Methods
[](attribute)
click to toggle source
# File lib/js_routes/configuration.rb, line 83 def [](attribute) public_send(attribute) end
assign(attributes)
click to toggle source
# File lib/js_routes/configuration.rb, line 67 def assign(attributes) if attributes attributes.each do |attribute, value| public_send(:"#{attribute}=", value) end end normalize_and_verify self end
dts?()
click to toggle source
# File lib/js_routes/configuration.rb, line 98 def dts? self.module_type === 'DTS' end
esm?()
click to toggle source
# File lib/js_routes/configuration.rb, line 93 def esm? module_type === 'ESM' end
merge(attributes)
click to toggle source
# File lib/js_routes/configuration.rb, line 88 def merge(attributes) clone.assign(attributes) end
modern?()
click to toggle source
# File lib/js_routes/configuration.rb, line 103 def modern? esm? || dts? end
output_file()
click to toggle source
# File lib/js_routes/configuration.rb, line 118 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()
click to toggle source
# File lib/js_routes/configuration.rb, line 108 def require_esm raise "ESM module type is required" unless modern? end
setup(&block)
click to toggle source
# File lib/js_routes/configuration.rb, line 78 def setup(&block) tap(&block) end
source_file()
click to toggle source
# File lib/js_routes/configuration.rb, line 113 def source_file File.dirname(__FILE__) + "/../" + default_file_name end
Protected Instance Methods
default_file_name()
click to toggle source
# File lib/js_routes/configuration.rb, line 143 def default_file_name dts? ? "routes.d.ts" : "routes.js" end
normalize()
click to toggle source
# File lib/js_routes/configuration.rb, line 148 def normalize self.module_type = module_type&.upcase || 'NIL' end
normalize_and_verify()
click to toggle source
# File lib/js_routes/configuration.rb, line 132 def normalize_and_verify normalize verify end
pathname(*parts)
click to toggle source
# File lib/js_routes/configuration.rb, line 138 def pathname(*parts) Pathname.new(File.join(*T.unsafe(parts))) end
verify()
click to toggle source
# File lib/js_routes/configuration.rb, line 153 def verify if module_type != 'NIL' && namespace raise "JsRoutes namespace option can only be used if module_type is nil" end end