Class: JsRoutes::Instance
- Inherits:
-
Object
- Object
- JsRoutes::Instance
show all
- Extended by:
- T::Sig
- Includes:
- Types
- Defined in:
- lib/js_routes/instance.rb
Overview
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
Instance Method Summary
collapse
Constructor Details
#initialize(**options) ⇒ Instance
Returns a new instance of Instance.
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
13
14
15
|
# File 'lib/js_routes/instance.rb', line 13
def configuration
@configuration
end
|
Instance Method Details
#banner ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/js_routes/instance.rb', line 56
def banner
banner = @configuration.banner
banner = banner.call if banner.is_a?(Proc)
return "" if banner.blank?
[
"/**",
*banner.split("\n").map { |line| " * #{line}" },
" */",
"",
].join("\n")
end
|
#generate ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/js_routes/instance.rb', line 25
def generate
application = T.unsafe(self.application)
if routes_from(application).empty?
if application.is_a?(Rails::Application)
if JsRoutes::Utils.rails_version >= Gem::Version.new("8.0.0")
T.unsafe(application).reload_routes_unless_loaded
else
T.unsafe(application).reload_routes!
end
end
end
unless @configuration.module_type == "NIL"
banner + jsr + routes_export
else
jsr.sub(/\A(\/\/[^\n]+\n)*;\n/, "")
end
end
|
#generate! ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/js_routes/instance.rb', line 69
def generate!
T.unsafe(Rails).configuration.after_initialize do
file_path = Rails.root.join(@configuration.output_file)
source_code = generate
next if File.exist?(file_path) && File.read(file_path) == source_code
File.open(file_path, 'w') do |f|
f.write source_code
end
end
end
|
#package ⇒ Object
49
50
51
52
53
|
# File 'lib/js_routes/instance.rb', line 49
def package
raise "Package generation requires module_type: 'PKG'" unless @configuration.pkg?
jsr
end
|
#package! ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/js_routes/instance.rb', line 88
def package!
raise "Package generation requires module_type: 'PKG'" unless @configuration.pkg?
file_path = Rails.root.join(@configuration.output_file)
source_code = package
return if File.exist?(file_path) && File.read(file_path) == source_code
File.open(file_path, 'w') do |f|
f.write source_code
end
end
|
#remove! ⇒ Object
104
105
106
107
108
|
# File 'lib/js_routes/instance.rb', line 104
def remove!
path = Rails.root.join(@configuration.output_file)
FileUtils.rm_rf(path)
FileUtils.rm_rf(path.sub(%r{\.js\z}, '.d.ts'))
end
|