solidus_support 0.4.1 → 0.5.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: ceefe11ac7e48cfcba96aec57eff516d8d517c48f990098645d380f5c33ad6b9
4
- data.tar.gz: 1ce25f4ff870f87f137ba021ee8db5db76bb6031ffb22e18f49cea21be3ac882
3
+ metadata.gz: e720d17f4c4d0b8dfb852da8ea260bbaa7c069b83b07e102b96633bb65ed9e18
4
+ data.tar.gz: 66726d7f7d4ef6acecb63024eb7ac54888efaddb597f997c9cbda545642a4101
5
5
  SHA512:
6
- metadata.gz: 4b9b82cf9add77927ae9a2b2b087c886dae93d4577a9daf58274464b07ab5fa6e89725ec32a558f1dd79f75b507ff908287a8b9af9ec5b146611fd270a900446
7
- data.tar.gz: 7e37c959b0790f36cdb89af526bf56b364b30356ed88c2888bce34c6b4984fc53631dec1c6acde601e64e0ba80a39a8dde84665cd64f7c30fa679542e4e87131
6
+ metadata.gz: 1b3061f16c942f99c9f6689f03e89875a1e88ff2c0761a5ad10020b7f9c80c2971a70590eeb0eca458929e86c3617ef56e2ade8a0f5f8a01e60e8c285704faa6
7
+ data.tar.gz: f22c1b1daa5f11853f1d2625750927349d3e8a2b36ed4eba3a4aea62276be3e9375b4ab19d1b8132644893038a2dc04ac065342dbb28e1146b974870c3ffeb1c
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.4.1](https://github.com/solidusio/solidus_support/tree/v0.4.1) (2020-01-16)
4
+
5
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.4.0...v0.4.1)
6
+
7
+ **Closed issues:**
8
+
9
+ - Should use require\_dependency instead of require/load [\#34](https://github.com/solidusio/solidus_support/issues/34)
10
+ - Add a LICENSE [\#20](https://github.com/solidusio/solidus_support/issues/20)
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Update solidus\_dev\_support [\#41](https://github.com/solidusio/solidus_support/pull/41) ([aldesantis](https://github.com/aldesantis))
15
+ - Replace manual cache checks w/ require\_dependency [\#39](https://github.com/solidusio/solidus_support/pull/39) ([elia](https://github.com/elia))
16
+ - Fixes isse when zeitwerk is not enabled [\#38](https://github.com/solidusio/solidus_support/pull/38) ([softr8](https://github.com/softr8))
17
+ - Spring cleaning [\#33](https://github.com/solidusio/solidus_support/pull/33) ([aldesantis](https://github.com/aldesantis))
18
+
3
19
  ## [v0.4.0](https://github.com/solidusio/solidus_support/tree/v0.4.0) (2019-12-16)
4
20
 
5
21
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.3.2...v0.4.0)
data/README.md CHANGED
@@ -38,7 +38,7 @@ module SolidusExtensionName
38
38
  class Engine < Rails::Engine
39
39
  engine_name 'solidus_extension_name'
40
40
 
41
- include SolidusSupport::EngineExtensions::Decorators
41
+ include SolidusSupport::EngineExtensions
42
42
 
43
43
  # ...
44
44
  end
@@ -57,6 +57,26 @@ end
57
57
  config.to_prepare(&method(:activate).to_proc)
58
58
  ```
59
59
 
60
+ #### Loading files conditionally
61
+
62
+ If you include `EngineExtensions` in your extension and structure your files according to the
63
+ expected paths, they will be loaded automagically only when the relevant Solidus engines are
64
+ available.
65
+
66
+ Here's what an example structure may look like:
67
+
68
+ - `lib/views/backend`: will only be added to the view paths when `solidus_backend` is available.
69
+ - `lib/controllers/backend`: will only be added to the controller paths when `solidus_backend` is
70
+ available.
71
+ - `lib/decorators/backend`: will only be added to the decorator paths when `solidus_backend` is
72
+ available.
73
+
74
+ The same goes for `frontend` and `api`.
75
+
76
+ We strongly recommend following this structure and making your extensions so that they're not
77
+ dependent on anything other than `solidus_core`, only augmenting the functionality of the other
78
+ engines when they are available.
79
+
60
80
  ## Development
61
81
 
62
82
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new
@@ -8,15 +8,12 @@ require 'solidus_core'
8
8
  module SolidusSupport
9
9
  class << self
10
10
  def solidus_gem_version
11
- if Spree.respond_to?(:solidus_gem_version)
12
- Spree.solidus_gem_version
13
- elsif Spree.respond_to?(:gem_version)
14
- # 1.1 doesn't have solidus_gem_version
15
- Gem::Version.new(Spree.solidus_version)
16
- else
17
- # 1.0 doesn't have gem_version
18
- Gem::Specification.detect { |x| x.name == 'solidus_core' }.version
19
- end
11
+ ActiveSupport::Deprecation.warn <<-WARN.squish, caller
12
+ SolidusSupport.solidus_gem_version is deprecated and will be removed
13
+ in solidus_support 1.0. Please use Spree.solidus_gem_version instead.
14
+ WARN
15
+
16
+ Spree.solidus_gem_version
20
17
  end
21
18
 
22
19
  def reset_spree_preferences_deprecated?
@@ -1,3 +1,76 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'engine_extensions/decorators'
3
+ module SolidusSupport
4
+ module EngineExtensions
5
+ include ActiveSupport::Deprecation::DeprecatedConstantAccessor
6
+ deprecate_constant 'Decorators', 'SolidusSupport::EngineExtensions'
7
+
8
+ def self.included(engine)
9
+ engine.extend ClassMethods
10
+
11
+ engine.class_eval do
12
+ config.to_prepare(&method(:activate))
13
+
14
+ enable_solidus_engine_support('backend') if SolidusSupport.backend_available?
15
+ enable_solidus_engine_support('frontend') if SolidusSupport.frontend_available?
16
+ enable_solidus_engine_support('api') if SolidusSupport.api_available?
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ def activate
22
+ if Rails.respond_to?(:autoloaders) && Rails.autoloaders.main
23
+ # Add decorators folder to the Rails autoloader. This tells Zeitwerk to treat paths
24
+ # such as app/decorators/controllers as roots.
25
+ solidus_decorators_root.glob('*') do |decorators_folder|
26
+ Rails.autoloaders.main.push_dir(decorators_folder)
27
+ end
28
+ end
29
+
30
+ load_solidus_decorators_from(solidus_decorators_root)
31
+ end
32
+
33
+ # Loads decorator files.
34
+ #
35
+ # This is needed since they are never explicitly referenced in the application code and
36
+ # won't be loaded by default. We need them to be executed regardless in order to decorate
37
+ # existing classes.
38
+ def load_solidus_decorators_from(path)
39
+ path.glob('**/*.rb') do |decorator_path|
40
+ require_dependency(decorator_path)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ # Returns the root for this engine's decorators.
47
+ #
48
+ # @return [Path]
49
+ def solidus_decorators_root
50
+ root.join('app/decorators')
51
+ end
52
+
53
+ # Enables support for a Solidus engine.
54
+ #
55
+ # This will tell Rails to:
56
+ #
57
+ # * add +lib/controllers/[engine]+ to the controller paths;
58
+ # * add +lib/views/[engine]+ to the view paths;
59
+ # * load the decorators in +lib/decorators/[engine]+.
60
+ #
61
+ # @see #load_solidus_decorators_from
62
+ def enable_solidus_engine_support(engine)
63
+ paths['app/controllers'] << "lib/controllers/#{engine}"
64
+ paths['app/views'] << "lib/views/#{engine}"
65
+
66
+ engine_context = self
67
+ config.to_prepare do
68
+ engine_context.instance_eval do
69
+ path = root.join("lib/decorators/#{engine}")
70
+ load_solidus_decorators_from(path)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusSupport
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
+ s.add_dependency 'activesupport', ['>= 5.2', '< 7.0.x']
25
+
24
26
  s.add_development_dependency 'bundler'
25
27
  s.add_development_dependency 'rake'
26
28
  s.add_development_dependency 'rspec-rails'
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.x
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.x
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: bundler
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -129,10 +149,10 @@ files:
129
149
  - bin/setup
130
150
  - lib/solidus_support.rb
131
151
  - lib/solidus_support/engine_extensions.rb
132
- - lib/solidus_support/engine_extensions/decorators.rb
133
152
  - lib/solidus_support/migration.rb
134
153
  - lib/solidus_support/version.rb
135
154
  - solidus_support.gemspec
155
+ - spec/examples.txt
136
156
  - spec/solidus_support_spec.rb
137
157
  - spec/spec_helper.rb
138
158
  - spec/support/dummy_app.rb
@@ -156,12 +176,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
176
  - !ruby/object:Gem::Version
157
177
  version: '0'
158
178
  requirements: []
159
- rubygems_version: 3.0.6
179
+ rubygems_version: 3.0.3
160
180
  signing_key:
161
181
  specification_version: 4
162
182
  summary: Common runtime helpers for Solidus extensions.
163
183
  test_files:
164
184
  - spec/spec_helper.rb
185
+ - spec/examples.txt
165
186
  - spec/solidus_support_spec.rb
166
187
  - spec/support/dummy_app.rb
167
188
  - spec/support/dummy_app/database.yml
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusSupport
4
- module EngineExtensions
5
- module Decorators
6
- def self.included(engine)
7
- engine.class_eval do
8
- extend ClassMethods
9
- config.to_prepare(&method(:activate).to_proc)
10
- end
11
- end
12
-
13
- module ClassMethods
14
- def activate
15
- base_path = root.join('app/decorators')
16
-
17
- if Rails.respond_to?(:autoloaders) && Rails.autoloaders.main
18
- # Add decorators folder to the Rails autoloader. This
19
- # allows Zeitwerk to resolve decorators paths correctly,
20
- # when used.
21
- Dir.glob(base_path.join('*')) do |decorators_folder|
22
- Rails.autoloaders.main.push_dir(decorators_folder)
23
- end
24
- end
25
-
26
- # Load decorator files. This is needed since they are
27
- # never explicitely referenced in the application code
28
- # and won't be loaded by default. We need them to be
29
- # executed anyway to extend exisiting classes.
30
- Dir.glob(base_path.join('**/*.rb')) do |decorator_path|
31
- require_dependency(decorator_path)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end