solidus_support 0.10.3 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/solidus_support/engine_extensions.rb +15 -19
- data/lib/solidus_support/version.rb +1 -1
- data/lib/solidus_support.rb +0 -1
- data/solidus_support.gemspec +3 -0
- metadata +30 -9
- data/lib/solidus_support/legacy_event_compat/bus.rb +0 -34
- data/lib/solidus_support/legacy_event_compat/subscriber.rb +0 -54
- data/lib/solidus_support/legacy_event_compat.rb +0 -47
- data/spec/solidus_support/legacy_event_compat/bus_spec.rb +0 -31
- data/spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 791e44bf714cfc82303b07994a80c9fa72c94e2ad92bf0e50cbf6d7fd67a6124
|
4
|
+
data.tar.gz: a0b7e7d7d9e551d99bbc93f12e1e16bfce0ffb4b63ec5c908a52bbde8fe78565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f1fef22c5003effc4611881f89a74da814fa354b68a23b70f96e00888dd0625f925cd41b60ec841cfb41ee2e91717bfd9e61e721c17e82aa30f2fe78a5bef5
|
7
|
+
data.tar.gz: 1f034253895ade97162295ef67797f0145b6c6ba153b3351f9a9fc83996dee4e926cd1f9ed9474478642d51760269aa2cf19185a43a10151d6d3a0cba89d7f85
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/deprecation"
|
4
|
+
require "flickwerk"
|
5
|
+
|
3
6
|
module SolidusSupport
|
4
7
|
module EngineExtensions
|
5
8
|
include ActiveSupport::Deprecation::DeprecatedConstantAccessor
|
@@ -7,6 +10,7 @@ module SolidusSupport
|
|
7
10
|
|
8
11
|
def self.included(engine)
|
9
12
|
engine.extend ClassMethods
|
13
|
+
engine.include Flickwerk
|
10
14
|
|
11
15
|
engine.class_eval do
|
12
16
|
solidus_decorators_root.glob('*') do |decorators_folder|
|
@@ -25,25 +29,6 @@ module SolidusSupport
|
|
25
29
|
module ClassMethods
|
26
30
|
def activate
|
27
31
|
load_solidus_decorators_from(solidus_decorators_root)
|
28
|
-
load_solidus_subscribers_from(solidus_subscribers_root)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Loads Solidus event subscriber files.
|
32
|
-
#
|
33
|
-
# This allows to add event subscribers to extensions without explicitly subscribing them,
|
34
|
-
# similarly to what happens in Solidus core.
|
35
|
-
def load_solidus_subscribers_from(path)
|
36
|
-
if SolidusSupport::LegacyEventCompat.using_legacy?
|
37
|
-
path.glob("**/*_subscriber.rb") do |subscriber_path|
|
38
|
-
require_dependency(subscriber_path)
|
39
|
-
end
|
40
|
-
|
41
|
-
if Spree::Event.respond_to?(:activate_all_subscribers)
|
42
|
-
Spree::Event.activate_all_subscribers
|
43
|
-
else
|
44
|
-
Spree::Event.subscribers.each(&:subscribe!)
|
45
|
-
end
|
46
|
-
end
|
47
32
|
end
|
48
33
|
|
49
34
|
# Loads decorator files.
|
@@ -122,6 +107,17 @@ module SolidusSupport
|
|
122
107
|
end
|
123
108
|
end
|
124
109
|
end
|
110
|
+
|
111
|
+
initializer "#{name}_#{engine}_patch_paths", before: "flickwerk.add_paths" do
|
112
|
+
patch_paths = root.join("lib/patches/#{engine}").glob("*")
|
113
|
+
Flickwerk.patch_paths += patch_paths
|
114
|
+
end
|
115
|
+
|
116
|
+
initializer "#{name}_#{engine}_user_patches", before: "flickwerk.add_patches" do
|
117
|
+
Flickwerk.patches.transform_keys! do |key|
|
118
|
+
key.gsub("Spree.user_class", Spree.user_class_name)
|
119
|
+
end
|
120
|
+
end
|
125
121
|
end
|
126
122
|
end
|
127
123
|
end
|
data/lib/solidus_support.rb
CHANGED
data/solidus_support.gemspec
CHANGED
@@ -28,6 +28,9 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
+
spec.add_dependency 'flickwerk', '~> 0.2.0'
|
32
|
+
spec.add_dependency 'solidus_core', '~> 4.1'
|
33
|
+
|
31
34
|
spec.add_development_dependency 'rails'
|
32
35
|
spec.add_development_dependency 'bundler'
|
33
36
|
spec.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
@@ -9,8 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: flickwerk
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.2.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.2.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: solidus_core
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '4.1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '4.1'
|
14
42
|
- !ruby/object:Gem::Dependency
|
15
43
|
name: rails
|
16
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,14 +174,9 @@ files:
|
|
146
174
|
- lib/solidus_support.rb
|
147
175
|
- lib/solidus_support/deprecator.rb
|
148
176
|
- lib/solidus_support/engine_extensions.rb
|
149
|
-
- lib/solidus_support/legacy_event_compat.rb
|
150
|
-
- lib/solidus_support/legacy_event_compat/bus.rb
|
151
|
-
- lib/solidus_support/legacy_event_compat/subscriber.rb
|
152
177
|
- lib/solidus_support/migration.rb
|
153
178
|
- lib/solidus_support/version.rb
|
154
179
|
- solidus_support.gemspec
|
155
|
-
- spec/solidus_support/legacy_event_compat/bus_spec.rb
|
156
|
-
- spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb
|
157
180
|
- spec/solidus_support_spec.rb
|
158
181
|
- spec/spec_helper.rb
|
159
182
|
- spec/support/dummy_app.rb
|
@@ -185,8 +208,6 @@ signing_key:
|
|
185
208
|
specification_version: 4
|
186
209
|
summary: Common runtime helpers for Solidus extensions.
|
187
210
|
test_files:
|
188
|
-
- spec/solidus_support/legacy_event_compat/bus_spec.rb
|
189
|
-
- spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb
|
190
211
|
- spec/solidus_support_spec.rb
|
191
212
|
- spec/spec_helper.rb
|
192
213
|
- spec/support/dummy_app.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SolidusSupport
|
4
|
-
module LegacyEventCompat
|
5
|
-
# Compatibility for some event-driven operations
|
6
|
-
module Bus
|
7
|
-
# Publication of an event
|
8
|
-
#
|
9
|
-
# If extensions want to support the legacy sytem, they need to use a
|
10
|
-
# compatible API. That means it's not possible to publish an instance as
|
11
|
-
# event, which is something supported by Omnes but not the legacy adapter.
|
12
|
-
# Instead, a payload can be given. E.g.:
|
13
|
-
#
|
14
|
-
# ```
|
15
|
-
# SolidusSupport::LegacyEventCompat::Bus.publish(:foo, bar: :baz)
|
16
|
-
# ```
|
17
|
-
#
|
18
|
-
# Legacy subscribers will receive an
|
19
|
-
# `ActiveSupport::Notifications::Fanout`, while omnes subscribers will get
|
20
|
-
# an `Omnes::UnstructuredEvent`. Both instances are compatible as they
|
21
|
-
# implement a `#payload` method.
|
22
|
-
#
|
23
|
-
# @param event_name [Symbol]
|
24
|
-
# @param payload [Hash<Symbol, Any>]
|
25
|
-
def self.publish(event_name, **payload)
|
26
|
-
if SolidusSupport::LegacyEventCompat.using_legacy?
|
27
|
-
Spree::Event.fire(event_name, payload)
|
28
|
-
else
|
29
|
-
Spree::Bus.publish(event_name, **payload, caller_location: caller_locations(1)[0])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
begin
|
4
|
-
require "omnes"
|
5
|
-
rescue LoadError
|
6
|
-
end
|
7
|
-
|
8
|
-
module SolidusSupport
|
9
|
-
module LegacyEventCompat
|
10
|
-
# Compatibility for subscriber modules
|
11
|
-
#
|
12
|
-
# Thanks to this module, extensions can create legacy subscriber modules
|
13
|
-
# (see {Spree::Event::Subscriber}) and translate them automatically to an
|
14
|
-
# {Omnes::Subscriber}). E.g.:
|
15
|
-
#
|
16
|
-
# ```
|
17
|
-
# module MyExtension
|
18
|
-
# module MySubscriber
|
19
|
-
# include Spree::Event::Subscriber
|
20
|
-
# include SolidusSupport::LegacyEventCompat::Subscriber
|
21
|
-
#
|
22
|
-
# event_action :order_finalized
|
23
|
-
#
|
24
|
-
# def order_finalized(event)
|
25
|
-
# event.payload[:order].do_something
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# MyExtension::MySubscriber.omnes_subscriber.subscribe_to(Spree::Bus)
|
31
|
-
# ```
|
32
|
-
#
|
33
|
-
# The generated omnes subscriptions will call the corresponding legacy
|
34
|
-
# subscriber method with the omnes event. It'll compatible as long as the
|
35
|
-
# omnes event responds to the `#payload` method (see
|
36
|
-
# {Omnes::UnstructuredEvent}).
|
37
|
-
module Subscriber
|
38
|
-
# @api private
|
39
|
-
ADAPTER = lambda do |legacy_subscriber, legacy_subscriber_method, _omnes_subscriber, omnes_event|
|
40
|
-
legacy_subscriber.send(legacy_subscriber_method, omnes_event)
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.included(legacy_subscriber)
|
44
|
-
legacy_subscriber.define_singleton_method(:omnes_subscriber) do
|
45
|
-
@omnes_subscriber ||= Class.new.include(::Omnes::Subscriber).tap do |subscriber|
|
46
|
-
legacy_subscriber.event_actions.each do |(legacy_subscriber_method, event_name)|
|
47
|
-
subscriber.handle(event_name.to_sym, with: ADAPTER.curry[legacy_subscriber, legacy_subscriber_method])
|
48
|
-
end
|
49
|
-
end.new
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'solidus_support/legacy_event_compat/bus'
|
4
|
-
require 'solidus_support/legacy_event_compat/subscriber'
|
5
|
-
|
6
|
-
module SolidusSupport
|
7
|
-
# Compatibility middleman for {Spree::Event} and {Spree::Bus}
|
8
|
-
#
|
9
|
-
# Solidus v3.2 changed to use [Omnes](https://github.com/nebulab/omnes) as the
|
10
|
-
# backbone for event-driven behavior (see {Spree::Bus}) by default. Before
|
11
|
-
# that, a custom adapter based on {ActiveSupport::Notifications} was used (see
|
12
|
-
# {Spree::Event}. Both systems are still supported on v3.2.
|
13
|
-
#
|
14
|
-
# This module provides compatibility support so that extensions can easily
|
15
|
-
# target both systems regardless of the underlying circumstances:
|
16
|
-
#
|
17
|
-
# - Solidus v3.2 with the new system.
|
18
|
-
# - Solidus v3.2 with the legacy system.
|
19
|
-
# - Solidus v2.9 to v3.1, when only {Spree::Event} existed.
|
20
|
-
# - Possible future versions of Solidus, whether the legacy system is
|
21
|
-
# eventually removed or not.
|
22
|
-
module LegacyEventCompat
|
23
|
-
# Returns whether the application is using the legacy event system
|
24
|
-
#
|
25
|
-
# @return [Boolean]
|
26
|
-
def self.using_legacy?
|
27
|
-
legacy_present? &&
|
28
|
-
(legacy_alone? ||
|
29
|
-
legacy_chosen?)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.legacy_present?
|
33
|
-
defined?(Spree::Event)
|
34
|
-
end
|
35
|
-
private_class_method :legacy_present?
|
36
|
-
|
37
|
-
def self.legacy_alone?
|
38
|
-
!Spree::Config.respond_to?(:use_legacy_events)
|
39
|
-
end
|
40
|
-
private_class_method :legacy_alone?
|
41
|
-
|
42
|
-
def self.legacy_chosen?
|
43
|
-
Spree::Config.use_legacy_events
|
44
|
-
end
|
45
|
-
private_class_method :legacy_chosen?
|
46
|
-
end
|
47
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe SolidusSupport::LegacyEventCompat::Bus do
|
4
|
-
describe '#publish' do
|
5
|
-
if SolidusSupport::LegacyEventCompat.using_legacy?
|
6
|
-
it 'forwards to Spree::Event' do
|
7
|
-
box = nil
|
8
|
-
subscription = Spree::Event.subscribe(:foo) { |event| box = event.payload[:bar] }
|
9
|
-
|
10
|
-
described_class.publish(:foo, bar: :baz)
|
11
|
-
|
12
|
-
expect(box).to be(:baz)
|
13
|
-
ensure
|
14
|
-
Spree::Event.unsubscribe(subscription)
|
15
|
-
end
|
16
|
-
else
|
17
|
-
it 'forwards to Spree::Bus' do
|
18
|
-
box = nil
|
19
|
-
Spree::Bus.register(:foo)
|
20
|
-
subscription = Spree::Bus.subscribe(:foo) { |event| box = event.payload[:bar] }
|
21
|
-
|
22
|
-
described_class.publish(:foo, bar: :baz)
|
23
|
-
|
24
|
-
expect(box).to be(:baz)
|
25
|
-
ensure
|
26
|
-
Spree::Bus.unsubscribe(subscription)
|
27
|
-
Spree::Bus.registry.unregister(:foo)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'omnes'
|
4
|
-
|
5
|
-
RSpec.describe SolidusSupport::LegacyEventCompat::Subscriber, if: Spree.solidus_version < Gem::Version.new("4.0.0.dev") do
|
6
|
-
subject { Module.new.include(Spree::Event::Subscriber).include(described_class) }
|
7
|
-
|
8
|
-
describe '#omnes_subscriber' do
|
9
|
-
it 'returns an Omnes::Subscriber' do
|
10
|
-
subject.module_eval do
|
11
|
-
event_action :foo
|
12
|
-
|
13
|
-
def foo(_event); end
|
14
|
-
end
|
15
|
-
|
16
|
-
expect(subject.omnes_subscriber.is_a?(Omnes::Subscriber)).to be(true)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'adds single-event definitions matching legacy event actions' do
|
20
|
-
subject.module_eval do
|
21
|
-
event_action :foo
|
22
|
-
|
23
|
-
def foo(_event); end
|
24
|
-
end
|
25
|
-
bus = Omnes::Bus.new
|
26
|
-
bus.register(:foo)
|
27
|
-
|
28
|
-
subscriptions = subject.omnes_subscriber.subscribe_to(bus)
|
29
|
-
|
30
|
-
event = Struct.new(:omnes_event_name).new(:foo)
|
31
|
-
expect(subscriptions.first.matches?(event)).to be(true)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'coerces event names given as Strings' do
|
35
|
-
subject.module_eval do
|
36
|
-
event_action 'foo'
|
37
|
-
|
38
|
-
def foo(_event); end
|
39
|
-
end
|
40
|
-
bus = Omnes::Bus.new
|
41
|
-
bus.register(:foo)
|
42
|
-
|
43
|
-
subscriptions = subject.omnes_subscriber.subscribe_to(bus)
|
44
|
-
|
45
|
-
event = Struct.new(:omnes_event_name).new(:foo)
|
46
|
-
expect(subscriptions.first.matches?(event)).to be(true)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'executes legacy event action methods as handlers with the omnes event' do
|
50
|
-
subject.module_eval do
|
51
|
-
event_action :foo
|
52
|
-
|
53
|
-
def foo(event)
|
54
|
-
event[:bar]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
bus = Omnes::Bus.new
|
58
|
-
bus.register(:foo)
|
59
|
-
|
60
|
-
subscriptions = subject.omnes_subscriber.subscribe_to(bus)
|
61
|
-
|
62
|
-
expect(
|
63
|
-
bus.publish(:foo, bar: :baz).executions.first.result
|
64
|
-
).to be(:baz)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'distingish when event name is given explicitly' do
|
68
|
-
subject.module_eval do
|
69
|
-
event_action :foo, event_name: :bar
|
70
|
-
|
71
|
-
def foo(_event)
|
72
|
-
:bar
|
73
|
-
end
|
74
|
-
end
|
75
|
-
bus = Omnes::Bus.new
|
76
|
-
bus.register(:bar)
|
77
|
-
|
78
|
-
subscriptions = subject.omnes_subscriber.subscribe_to(bus)
|
79
|
-
|
80
|
-
expect(
|
81
|
-
bus.publish(:bar).executions.first.result
|
82
|
-
).to be(:bar)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "returns the same omnes subscriber instance if called again" do
|
86
|
-
expect(subject.omnes_subscriber).to be(subject.omnes_subscriber)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "doesn't fail when no event action has been defined" do
|
90
|
-
expect { subject.omnes_subscriber }.not_to raise_error
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|