solidus_support 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a0741932321e5bc770d8d9fa4c4d178eaa71268ca2ffafddb03a269d48bb9ee
4
- data.tar.gz: 32b5a77f1610a7695a32a9bfe9ebf1ea632d14aefce3a7552c6ecbe09f881e33
3
+ metadata.gz: 4ceec9839b2660f01e5ab654be83da6acc61193f3962f58cfadd38d8b6595815
4
+ data.tar.gz: afdb9b7b6cb8cda221510f414226d4f1516208439e8194b2f9256648659bdf9d
5
5
  SHA512:
6
- metadata.gz: 0d05ddfde94137a189d0b11dd88774c753d271142e91df0576d886a0e36268f6c59430e880dbc1eb5249418d464f9805a17b4dd56fcc65081dff44ef61350726
7
- data.tar.gz: 4322be2a95d7e24ad6c41b9f789d71d092aa8847b795182bf8d84a776fbaada9452f3e330416955d3bd06b2d23ba6d2b978aab171803bfa3c36c7342ee3b0804
6
+ metadata.gz: 41d2cc9590d3f1d8e5aaff104d627023d43792a83cd41dfb5741cd307cd3b7154b8c350bd49f79b8383f1f618387c7bbb0b979b5c95596f695b0de06165c057e
7
+ data.tar.gz: 04577ebefdf6ac982cf7ba79633be516da1baf9f676618e5da8b80e1362f37f5d59077a30d1025549c1eb11bf2f597338798578ff3e229e27095292ffaa3d461
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ when 'mysql'
12
12
  when 'postgresql'
13
13
  gem 'pg'
14
14
  else
15
- gem 'sqlite3'
15
+ gem 'sqlite3', '~> 1.4'
16
16
  end
17
17
 
18
18
  gemspec
@@ -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.
@@ -53,7 +38,7 @@ module SolidusSupport
53
38
  # existing classes.
54
39
  def load_solidus_decorators_from(path)
55
40
  path.glob('**/*.rb') do |decorator_path|
56
- require_dependency(decorator_path)
41
+ load(decorator_path)
57
42
  end
58
43
  end
59
44
 
@@ -122,6 +107,17 @@ module SolidusSupport
122
107
  end
123
108
  end
124
109
  end
110
+
111
+ initializer "#{name}_#{engine}_patch_paths", after: "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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusSupport
4
- VERSION = '0.10.2'
4
+ VERSION = '0.11.0'
5
5
  end
@@ -3,7 +3,6 @@
3
3
  require 'solidus_support/version'
4
4
  require 'solidus_support/deprecator'
5
5
  require 'solidus_support/migration'
6
- require 'solidus_support/legacy_event_compat'
7
6
  require 'solidus_support/engine_extensions'
8
7
  require 'solidus_core'
9
8
 
@@ -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.10.2
4
+ version: 0.11.0
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-04-18 00:00:00.000000000 Z
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
@@ -180,13 +203,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
203
  - !ruby/object:Gem::Version
181
204
  version: '0'
182
205
  requirements: []
183
- rubygems_version: 3.5.3
206
+ rubygems_version: 3.5.22
184
207
  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