stimulus_reflex 3.4.0.pre8 → 3.5.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of stimulus_reflex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +639 -463
- data/CODE_OF_CONDUCT.md +6 -0
- data/Gemfile.lock +103 -100
- data/LATEST +1 -0
- data/README.md +14 -13
- data/app/channels/stimulus_reflex/channel.rb +62 -67
- data/lib/generators/USAGE +1 -1
- data/lib/generators/stimulus_reflex/{config_generator.rb → initializer_generator.rb} +3 -3
- data/lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt +3 -2
- data/lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +14 -0
- data/lib/stimulus_reflex.rb +11 -3
- data/lib/stimulus_reflex/broadcasters/broadcaster.rb +7 -4
- data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +2 -2
- data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +12 -5
- data/lib/stimulus_reflex/cable_ready_channels.rb +30 -6
- data/lib/stimulus_reflex/callbacks.rb +98 -0
- data/lib/stimulus_reflex/concern_enhancer.rb +37 -0
- data/lib/stimulus_reflex/configuration.rb +3 -1
- data/lib/stimulus_reflex/element.rb +31 -7
- data/lib/stimulus_reflex/policies/reflex_invocation_policy.rb +28 -0
- data/lib/stimulus_reflex/reflex.rb +57 -57
- data/lib/stimulus_reflex/reflex_data.rb +79 -0
- data/lib/stimulus_reflex/reflex_factory.rb +31 -0
- data/lib/stimulus_reflex/request_parameters.rb +19 -0
- data/lib/stimulus_reflex/{logger.rb → utils/logger.rb} +6 -8
- data/lib/stimulus_reflex/{sanity_checker.rb → utils/sanity_checker.rb} +65 -10
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/tasks/stimulus_reflex/install.rake +14 -7
- data/test/broadcasters/broadcaster_test.rb +2 -0
- data/test/broadcasters/broadcaster_test_case.rb +3 -1
- data/test/broadcasters/nothing_broadcaster_test.rb +7 -3
- data/test/broadcasters/page_broadcaster_test.rb +10 -4
- data/test/broadcasters/selector_broadcaster_test.rb +173 -55
- data/test/callbacks_test.rb +652 -0
- data/test/concern_enhancer_test.rb +54 -0
- data/test/element_test.rb +181 -0
- data/test/reflex_test.rb +7 -1
- data/test/test_helper.rb +10 -0
- data/test/tmp/app/reflexes/application_reflex.rb +1 -1
- data/test/tmp/app/reflexes/demo_reflex.rb +3 -2
- metadata +45 -36
- data/package.json +0 -57
- data/stimulus_reflex.gemspec +0 -40
- data/tags +0 -139
- data/yarn.lock +0 -4711
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StimulusReflex
|
4
|
+
class ReflexMethodInvocationPolicy
|
5
|
+
attr_reader :arguments, :required_params, :optional_params
|
6
|
+
|
7
|
+
def initialize(method, arguments)
|
8
|
+
@arguments = arguments
|
9
|
+
@required_params = method.parameters.select { |(kind, _)| kind == :req }
|
10
|
+
@optional_params = method.parameters.select { |(kind, _)| kind == :opt }
|
11
|
+
end
|
12
|
+
|
13
|
+
def no_arguments?
|
14
|
+
arguments.size == 0 && required_params.size == 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def arguments?
|
18
|
+
arguments.size >= required_params.size && arguments.size <= required_params.size + optional_params.size
|
19
|
+
end
|
20
|
+
|
21
|
+
def unknown?
|
22
|
+
return false if no_arguments?
|
23
|
+
return false if arguments?
|
24
|
+
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,49 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
ClientAttributes = Struct.new(:reflex_id, :reflex_controller, :
|
3
|
+
ClientAttributes = Struct.new(:reflex_id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, keyword_init: true)
|
4
4
|
|
5
5
|
class StimulusReflex::Reflex
|
6
6
|
include ActiveSupport::Rescuable
|
7
|
-
include
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class << self
|
12
|
-
def before_reflex(*args, &block)
|
13
|
-
add_callback(:before, *args, &block)
|
14
|
-
end
|
15
|
-
|
16
|
-
def after_reflex(*args, &block)
|
17
|
-
add_callback(:after, *args, &block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def around_reflex(*args, &block)
|
21
|
-
add_callback(:around, *args, &block)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def add_callback(kind, *args, &block)
|
27
|
-
options = args.extract_options!
|
28
|
-
options.assert_valid_keys :if, :unless, :only, :except
|
29
|
-
set_callback(*[:process, kind, args, normalize_callback_options!(options)].flatten, &block)
|
30
|
-
end
|
31
|
-
|
32
|
-
def normalize_callback_options!(options)
|
33
|
-
normalize_callback_option! options, :only, :if
|
34
|
-
normalize_callback_option! options, :except, :unless
|
35
|
-
options
|
36
|
-
end
|
37
|
-
|
38
|
-
def normalize_callback_option!(options, from, to)
|
39
|
-
if (from = options.delete(from))
|
40
|
-
from_set = Array(from).map(&:to_s).to_set
|
41
|
-
from = proc { |reflex| from_set.include? reflex.method_name }
|
42
|
-
options[to] = Array(options[to]).unshift(from)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
7
|
+
include StimulusReflex::Callbacks
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include CableReady::Identifiable
|
46
10
|
|
11
|
+
attr_accessor :payload
|
47
12
|
attr_reader :cable_ready, :channel, :url, :element, :selectors, :method_name, :broadcaster, :client_attributes, :logger
|
48
13
|
|
49
14
|
alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name
|
@@ -51,10 +16,20 @@ class StimulusReflex::Reflex
|
|
51
16
|
delegate :connection, :stream_name, to: :channel
|
52
17
|
delegate :controller_class, :flash, :session, to: :request
|
53
18
|
delegate :broadcast, :broadcast_message, to: :broadcaster
|
54
|
-
delegate :reflex_id, :reflex_controller, :
|
55
|
-
delegate :render, to: :controller_class
|
19
|
+
delegate :reflex_id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, to: :client_attributes
|
56
20
|
|
57
21
|
def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, params: {}, client_attributes: {})
|
22
|
+
if is_a? CableReady::Broadcaster
|
23
|
+
message = <<~MSG
|
24
|
+
|
25
|
+
#{self.class.name} includes CableReady::Broadcaster, and you need to remove it.
|
26
|
+
Reflexes have their own CableReady interface. You can just assume that it's present.
|
27
|
+
See https://docs.stimulusreflex.com/rtfm/cableready#using-cableready-inside-a-reflex-action for more details.
|
28
|
+
|
29
|
+
MSG
|
30
|
+
raise TypeError.new(message.strip)
|
31
|
+
end
|
32
|
+
|
58
33
|
@channel = channel
|
59
34
|
@url = url
|
60
35
|
@element = element
|
@@ -64,7 +39,8 @@ class StimulusReflex::Reflex
|
|
64
39
|
@broadcaster = StimulusReflex::PageBroadcaster.new(self)
|
65
40
|
@logger = StimulusReflex::Logger.new(self)
|
66
41
|
@client_attributes = ClientAttributes.new(client_attributes)
|
67
|
-
@cable_ready = StimulusReflex::CableReadyChannels.new(stream_name)
|
42
|
+
@cable_ready = StimulusReflex::CableReadyChannels.new(stream_name, reflex_id)
|
43
|
+
@payload = {}
|
68
44
|
self.params
|
69
45
|
end
|
70
46
|
|
@@ -87,19 +63,25 @@ class StimulusReflex::Reflex
|
|
87
63
|
)
|
88
64
|
|
89
65
|
env = connection.env.merge(mock_env)
|
66
|
+
|
67
|
+
middleware = StimulusReflex.config.middleware
|
68
|
+
|
69
|
+
if middleware.any?
|
70
|
+
stack = middleware.build(Rails.application.routes)
|
71
|
+
stack.call(env)
|
72
|
+
end
|
73
|
+
|
90
74
|
req = ActionDispatch::Request.new(env)
|
91
75
|
|
92
|
-
|
93
|
-
|
94
|
-
|
76
|
+
# fetch path params (controller, action, ...) and apply them
|
77
|
+
request_params = StimulusReflex::RequestParameters.new(params: @params, req: req, url: url)
|
78
|
+
req = request_params.apply!
|
95
79
|
|
96
|
-
req
|
97
|
-
req.env["action_dispatch.request.parameters"] = req.parameters.merge(@params)
|
98
|
-
req.tap { |r| r.session.send :load! }
|
80
|
+
req
|
99
81
|
end
|
100
82
|
end
|
101
83
|
|
102
|
-
def morph(selectors, html =
|
84
|
+
def morph(selectors, html = nil)
|
103
85
|
case selectors
|
104
86
|
when :page
|
105
87
|
raise StandardError.new("Cannot call :page morph after :#{broadcaster.to_sym} morph") unless broadcaster.page?
|
@@ -114,16 +96,25 @@ class StimulusReflex::Reflex
|
|
114
96
|
end
|
115
97
|
|
116
98
|
def controller
|
117
|
-
@controller ||=
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
c.set_request! request
|
122
|
-
c.set_response! controller_class.make_response!(request)
|
123
|
-
end
|
99
|
+
@controller ||= controller_class.new.tap do |c|
|
100
|
+
c.instance_variable_set :@stimulus_reflex, true
|
101
|
+
c.set_request! request
|
102
|
+
c.set_response! controller_class.make_response!(request)
|
124
103
|
end
|
104
|
+
|
105
|
+
instance_variables.each { |name| @controller.instance_variable_set name, instance_variable_get(name) }
|
106
|
+
@controller
|
107
|
+
end
|
108
|
+
|
109
|
+
def controller?
|
110
|
+
!!defined? @controller
|
125
111
|
end
|
126
112
|
|
113
|
+
def render(*args)
|
114
|
+
controller_class.renderer.new(connection.env.merge("SCRIPT_NAME" => "")).render(*args)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Invoke the reflex action specified by `name` and run all callbacks
|
127
118
|
def process(name, *args)
|
128
119
|
reflex_invoked = false
|
129
120
|
result = run_callbacks(:process) {
|
@@ -147,4 +138,13 @@ class StimulusReflex::Reflex
|
|
147
138
|
def params
|
148
139
|
@_params ||= ActionController::Parameters.new(request.parameters)
|
149
140
|
end
|
141
|
+
|
142
|
+
# morphdom needs content to be wrapped in an element with the same id when children_only: true
|
143
|
+
# Oddly, it doesn't matter if the target element is a div! See: https://docs.stimulusreflex.com/appendices/troubleshooting#different-element-type-altogether-who-cares-so-long-as-the-css-selector-matches
|
144
|
+
# Used internally to allow automatic partial collection rendering, but also useful to library users
|
145
|
+
# eg. `morph dom_id(@posts), render_collection(@posts)`
|
146
|
+
def render_collection(resource, content = nil)
|
147
|
+
content ||= render(resource)
|
148
|
+
tag.div(content.html_safe, id: dom_id(resource).from(1))
|
149
|
+
end
|
150
150
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class StimulusReflex::ReflexData
|
2
|
+
attr_reader :data
|
3
|
+
|
4
|
+
def initialize(data)
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def reflex_name
|
9
|
+
reflex_name = target.split("#").first
|
10
|
+
reflex_name = reflex_name.camelize
|
11
|
+
reflex_name.end_with?("Reflex") ? reflex_name : "#{reflex_name}Reflex"
|
12
|
+
end
|
13
|
+
|
14
|
+
def selectors
|
15
|
+
selectors = (data["selectors"] || []).select(&:present?)
|
16
|
+
selectors = data["selectors"] = ["body"] if selectors.blank?
|
17
|
+
selectors
|
18
|
+
end
|
19
|
+
|
20
|
+
def target
|
21
|
+
data["target"].to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_name
|
25
|
+
target.split("#").second
|
26
|
+
end
|
27
|
+
|
28
|
+
def arguments
|
29
|
+
(data["args"] || []).map { |arg| object_with_indifferent_access arg } || []
|
30
|
+
end
|
31
|
+
|
32
|
+
def url
|
33
|
+
data["url"].to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def element
|
37
|
+
StimulusReflex::Element.new(data)
|
38
|
+
end
|
39
|
+
|
40
|
+
def permanent_attribute_name
|
41
|
+
data["permanentAttributeName"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def form_data
|
45
|
+
Rack::Utils.parse_nested_query(data["formData"])
|
46
|
+
end
|
47
|
+
|
48
|
+
def form_params
|
49
|
+
form_data.deep_merge(data["params"] || {})
|
50
|
+
end
|
51
|
+
|
52
|
+
def reflex_id
|
53
|
+
data["reflexId"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def tab_id
|
57
|
+
data["tabId"]
|
58
|
+
end
|
59
|
+
|
60
|
+
def xpath_controller
|
61
|
+
data["xpathController"]
|
62
|
+
end
|
63
|
+
|
64
|
+
def xpath_element
|
65
|
+
data["xpathElement"]
|
66
|
+
end
|
67
|
+
|
68
|
+
def reflex_controller
|
69
|
+
data["reflexController"]
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def object_with_indifferent_access(object)
|
75
|
+
return object.with_indifferent_access if object.respond_to?(:with_indifferent_access)
|
76
|
+
object.map! { |obj| object_with_indifferent_access obj } if object.is_a?(Array)
|
77
|
+
object
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class StimulusReflex::ReflexFactory
|
2
|
+
class << self
|
3
|
+
attr_reader :reflex_data
|
4
|
+
|
5
|
+
def create_reflex_from_data(channel, reflex_data)
|
6
|
+
@reflex_data = reflex_data
|
7
|
+
reflex_class.new(channel,
|
8
|
+
url: reflex_data.url,
|
9
|
+
element: reflex_data.element,
|
10
|
+
selectors: reflex_data.selectors,
|
11
|
+
method_name: reflex_data.method_name,
|
12
|
+
params: reflex_data.form_params,
|
13
|
+
client_attributes: {
|
14
|
+
reflex_id: reflex_data.reflex_id,
|
15
|
+
tab_id: reflex_data.tab_id,
|
16
|
+
xpath_controller: reflex_data.xpath_controller,
|
17
|
+
xpath_element: reflex_data.xpath_element,
|
18
|
+
reflex_controller: reflex_data.reflex_controller,
|
19
|
+
permanent_attribute_name: reflex_data.permanent_attribute_name
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def reflex_class
|
24
|
+
reflex_data.reflex_name.constantize.tap { |klass| raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(klass) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def is_reflex?(klass)
|
28
|
+
klass.ancestors.include? StimulusReflex::Reflex
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module StimulusReflex
|
2
|
+
class RequestParameters
|
3
|
+
def initialize(params:, req:, url:)
|
4
|
+
@params = params
|
5
|
+
@req = req
|
6
|
+
@url = url
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply!
|
10
|
+
path_params = Rails.application.routes.recognize_path_with_request(@req, @url, @req.env[:extras] || {})
|
11
|
+
path_params[:controller] = path_params[:controller].force_encoding("UTF-8")
|
12
|
+
path_params[:action] = path_params[:action].force_encoding("UTF-8")
|
13
|
+
|
14
|
+
@req.env.merge(ActionDispatch::Http::Parameters::PARAMETERS_KEY => path_params)
|
15
|
+
@req.env["action_dispatch.request.parameters"] = @req.parameters.merge(@params)
|
16
|
+
@req.tap { |r| r.session.send :load! }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -12,12 +12,10 @@ module StimulusReflex
|
|
12
12
|
def print
|
13
13
|
return unless config_logging.instance_of?(Proc)
|
14
14
|
|
15
|
-
puts
|
16
15
|
reflex.broadcaster.operations.each do
|
17
16
|
puts instance_eval(&config_logging) + "\e[0m"
|
18
17
|
@current_operation += 1
|
19
18
|
end
|
20
|
-
puts
|
21
19
|
end
|
22
20
|
|
23
21
|
private
|
@@ -79,22 +77,22 @@ module StimulusReflex
|
|
79
77
|
Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
80
78
|
end
|
81
79
|
|
82
|
-
def method_missing
|
83
|
-
return send(
|
80
|
+
def method_missing(name, *args)
|
81
|
+
return send(name) if private_instance_methods.include?(name.to_sym)
|
84
82
|
|
85
83
|
reflex.connection.identifiers.each do |identifier|
|
86
84
|
ident = reflex.connection.send(identifier)
|
87
|
-
return ident.send(
|
85
|
+
return ident.send(name) if ident.respond_to?(:attributes) && ident.attributes.key?(name.to_s)
|
88
86
|
end
|
89
87
|
"-"
|
90
88
|
end
|
91
89
|
|
92
|
-
def respond_to_missing?
|
93
|
-
return true if private_instance_methods.include?(
|
90
|
+
def respond_to_missing?(name, include_all)
|
91
|
+
return true if private_instance_methods.include?(name.to_sym)
|
94
92
|
|
95
93
|
reflex.connection.identifiers.each do |identifier|
|
96
94
|
ident = reflex.connection.send(identifier)
|
97
|
-
return true if ident.respond_to?(:attributes) && ident.attributes.key?(
|
95
|
+
return true if ident.respond_to?(:attributes) && ident.attributes.key?(name.to_s)
|
98
96
|
end
|
99
97
|
false
|
100
98
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class StimulusReflex::SanityChecker
|
4
|
+
LATEST_VERSION_FORMAT = /^(\d+\.\d+\.\d+)$/
|
5
|
+
NODE_VERSION_FORMAT = /(\d+\.\d+\.\d+.*):/
|
4
6
|
JSON_VERSION_FORMAT = /(\d+\.\d+\.\d+.*)"/
|
5
7
|
|
6
8
|
class << self
|
@@ -12,6 +14,8 @@ class StimulusReflex::SanityChecker
|
|
12
14
|
instance = new
|
13
15
|
instance.check_caching_enabled
|
14
16
|
instance.check_javascript_package_version
|
17
|
+
instance.check_default_url_config
|
18
|
+
instance.check_new_version_available
|
15
19
|
end
|
16
20
|
|
17
21
|
private
|
@@ -23,44 +27,80 @@ class StimulusReflex::SanityChecker
|
|
23
27
|
end
|
24
28
|
|
25
29
|
def called_by_generate_config?
|
26
|
-
ARGV.include? "stimulus_reflex:
|
30
|
+
ARGV.include? "stimulus_reflex:initializer"
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def check_caching_enabled
|
31
35
|
unless caching_enabled?
|
32
36
|
warn_and_exit <<~WARN
|
33
|
-
|
37
|
+
StimulusReflex requires caching to be enabled. Caching allows the session to be modified during ActionCable requests.
|
34
38
|
To enable caching in development, run:
|
35
|
-
|
39
|
+
rails dev:cache
|
36
40
|
WARN
|
37
41
|
end
|
38
42
|
|
39
43
|
unless not_null_store?
|
40
44
|
warn_and_exit <<~WARN
|
41
|
-
|
45
|
+
StimulusReflex requires caching to be enabled. Caching allows the session to be modified during ActionCable requests.
|
42
46
|
But your config.cache_store is set to :null_store, so it won't work.
|
43
47
|
WARN
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
51
|
+
def check_default_url_config
|
52
|
+
unless default_url_config_set?
|
53
|
+
warn_and_exit <<~WARN
|
54
|
+
StimulusReflex strongly suggests that you set default_url_options in your environment files.
|
55
|
+
Otherwise, ActionController and ActionMailer will default to example.com when rendering route helpers.
|
56
|
+
You can set your URL options in config/environments/#{Rails.env}.rb
|
57
|
+
config.action_controller.default_url_options = {host: "localhost", port: 3000}
|
58
|
+
config.action_mailer.default_url_options = {host: "localhost", port: 3000}
|
59
|
+
Please update every environment with the appropriate URL. Typically, no port is necessary in production.
|
60
|
+
WARN
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
47
64
|
def check_javascript_package_version
|
48
65
|
if javascript_package_version.nil?
|
49
66
|
warn_and_exit <<~WARN
|
50
|
-
Can't locate the stimulus_reflex
|
67
|
+
Can't locate the stimulus_reflex npm package.
|
51
68
|
Either add it to your package.json as a dependency or use "yarn link stimulus_reflex" if you are doing development.
|
52
69
|
WARN
|
53
70
|
end
|
54
71
|
|
55
72
|
unless javascript_version_matches?
|
56
73
|
warn_and_exit <<~WARN
|
57
|
-
The
|
58
|
-
To update the
|
59
|
-
|
74
|
+
The stimulus_reflex npm package version (#{javascript_package_version}) does not match the Rubygem version (#{gem_version}).
|
75
|
+
To update the stimulus_reflex npm package:
|
76
|
+
yarn upgrade stimulus_reflex@#{gem_version}
|
60
77
|
WARN
|
61
78
|
end
|
62
79
|
end
|
63
80
|
|
81
|
+
def check_new_version_available
|
82
|
+
return unless Rails.env.development?
|
83
|
+
return if StimulusReflex.config.on_new_version_available == :ignore
|
84
|
+
return unless using_stable_release
|
85
|
+
begin
|
86
|
+
latest_version = URI.open("https://raw.githubusercontent.com/stimulusreflex/stimulus_reflex/master/LATEST", open_timeout: 1, read_timeout: 1).read.strip
|
87
|
+
if latest_version != StimulusReflex::VERSION
|
88
|
+
puts <<~WARN
|
89
|
+
|
90
|
+
There is a new version of StimulusReflex available!
|
91
|
+
Current: #{StimulusReflex::VERSION} Latest: #{latest_version}
|
92
|
+
|
93
|
+
If you upgrade, it is very important that you update BOTH Gemfile and package.json
|
94
|
+
Then, run `bundle install && yarn install` to update to #{latest_version}.
|
95
|
+
|
96
|
+
WARN
|
97
|
+
exit if StimulusReflex.config.on_new_version_available == :exit
|
98
|
+
end
|
99
|
+
rescue
|
100
|
+
puts "StimulusReflex #{StimulusReflex::VERSION} update check skipped: connection timeout"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
64
104
|
private
|
65
105
|
|
66
106
|
def caching_enabled?
|
@@ -71,10 +111,20 @@ class StimulusReflex::SanityChecker
|
|
71
111
|
Rails.application.config.cache_store != :null_store
|
72
112
|
end
|
73
113
|
|
114
|
+
def default_url_config_set?
|
115
|
+
Rails.application.config.action_controller.default_url_options
|
116
|
+
end
|
117
|
+
|
74
118
|
def javascript_version_matches?
|
75
119
|
javascript_package_version == gem_version
|
76
120
|
end
|
77
121
|
|
122
|
+
def using_stable_release
|
123
|
+
stable = StimulusReflex::VERSION.match?(LATEST_VERSION_FORMAT)
|
124
|
+
puts "StimulusReflex #{StimulusReflex::VERSION} update check skipped: pre-release build" unless stable
|
125
|
+
stable
|
126
|
+
end
|
127
|
+
|
78
128
|
def gem_version
|
79
129
|
@_gem_version ||= StimulusReflex::VERSION.gsub(".pre", "-pre")
|
80
130
|
end
|
@@ -86,6 +136,8 @@ class StimulusReflex::SanityChecker
|
|
86
136
|
def find_javascript_package_version
|
87
137
|
if (match = search_file(package_json_path, regex: /version/))
|
88
138
|
match[JSON_VERSION_FORMAT, 1]
|
139
|
+
elsif (match = search_file(yarn_lock_path, regex: /^stimulus_reflex/))
|
140
|
+
match[NODE_VERSION_FORMAT, 1]
|
89
141
|
end
|
90
142
|
end
|
91
143
|
|
@@ -98,6 +150,10 @@ class StimulusReflex::SanityChecker
|
|
98
150
|
Rails.root.join("node_modules", "stimulus_reflex", "package.json")
|
99
151
|
end
|
100
152
|
|
153
|
+
def yarn_lock_path
|
154
|
+
Rails.root.join("yarn.lock")
|
155
|
+
end
|
156
|
+
|
101
157
|
def initializer_path
|
102
158
|
@_initializer_path ||= Rails.root.join("config", "initializers", "stimulus_reflex.rb")
|
103
159
|
end
|
@@ -111,7 +167,6 @@ class StimulusReflex::SanityChecker
|
|
111
167
|
def exit_with_info
|
112
168
|
puts
|
113
169
|
|
114
|
-
# bundle exec rails generate stimulus_reflex:config
|
115
170
|
if File.exist?(initializer_path)
|
116
171
|
puts <<~INFO
|
117
172
|
If you know what you are doing and you want to start the application anyway,
|
@@ -132,7 +187,7 @@ class StimulusReflex::SanityChecker
|
|
132
187
|
|
133
188
|
Then open your initializer at
|
134
189
|
|
135
|
-
|
190
|
+
#{initializer_path}
|
136
191
|
|
137
192
|
and then add the following directive:
|
138
193
|
|