decorators 2.0.5 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6091a1ade1ac5605813292d8bd527d7f4b38aacb9a2109a9c64c19b119d3cf80
4
- data.tar.gz: ad9c81250cf2fa82af1b4494efa58a7f9b51c35f419ee94afd81f1948f4dbfab
3
+ metadata.gz: b9efa7db170a09a587fead6631846e7212ad98fc9b814de4c59845b1ee397163
4
+ data.tar.gz: 8dc05592f028f78da76e3f2fdb44b78f19960957e8ba5166d43a7101ba0fa2c0
5
5
  SHA512:
6
- metadata.gz: fdf6cf64ee8d6450c0f5a3b3c1e44d5e9e799774635906265859852819c04d92b97df1f29c28b776a73893536a8e8c5a023e35cf1ee3c6e22900d77d0d4ecf57
7
- data.tar.gz: 2b1933cde307d5ce6e5bf9f5a6190e9923e16780f95ba9fb6e9bf83cc6b33a6ec63c077eb9b11ab0377eaba2d90953843516f7a2958fa965be2f1a3a42adb262
6
+ metadata.gz: 672b0091b73016852f0076508b6145bf64f4bd56ba9ccda823e9b10d30a2e019d3999c84785e63d1b1911aa9c8efb4c1405500eb3513d4c60f0e24709c768a7b
7
+ data.tar.gz: d04d6dc7df0c86f11e7e808922f013560a72c6023b771347bc9e5ef31140bbf5b8627fdf6d2b91b430a99b01e5374f8c63d024cde8377a49cc6d5e9079771897
@@ -1,9 +1,11 @@
1
- require 'pathname'
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
2
4
 
3
5
  module Decorators
4
6
  class Paths
5
-
6
7
  attr_reader :registered
8
+
7
9
  def initialize(*args)
8
10
  @registered = Array.new(*args)
9
11
  end
@@ -11,6 +13,5 @@ module Decorators
11
13
  def register!(path)
12
14
  @registered << Pathname.new(path)
13
15
  end
14
-
15
16
  end
16
17
  end
@@ -1,8 +1,9 @@
1
- require 'rails'
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
2
4
 
3
5
  module Decorators
4
6
  class Railtie < Rails::Railtie
5
-
6
7
  config.before_initialize do |app|
7
8
  loader = proc { Decorators.load!(app.config.cache_classes) }
8
9
 
@@ -12,6 +13,5 @@ module Decorators
12
13
  app.config.to_prepare(&loader)
13
14
  end
14
15
  end
15
-
16
16
  end
17
17
  end
data/lib/decorators.rb CHANGED
@@ -1,45 +1,69 @@
1
- module Decorators
2
- require 'decorators/paths'
1
+ # frozen_string_literal: true
2
+
3
+ require "decorators/paths"
4
+ require "decorators/railtie"
3
5
 
6
+ module Decorators
4
7
  class << self
5
8
  def load!(cache_classes)
9
+ decorators_with_argument_errors = []
6
10
  decorators.each do |decorator|
7
- if cache_classes
8
- require decorator
9
- else
10
- load decorator
11
- end
11
+ load_decorator(decorator, cache_classes)
12
+ rescue ArgumentError
13
+ decorators_with_argument_errors << decorator
14
+ end
15
+
16
+ decorators_with_argument_errors.each do |decorator|
17
+ load_decorator(decorator, cache_classes)
12
18
  end
13
19
  end
14
20
 
15
21
  def decorators
16
- paths.registered.map { |path| find_decorators_in_path(path) }.flatten.uniq
22
+ paths.registered.map(&method(:find_decorators_in_path)).flatten.uniq
17
23
  end
18
24
 
19
25
  def register!(*paths_to_register)
20
26
  paths_to_register.flatten.map do |path|
21
27
  paths.register! path
28
+ ignore_in_autoloader(path)
22
29
  end
23
30
  end
24
31
 
25
- protected
32
+ private
33
+
26
34
  def paths
27
35
  @paths ||= Paths.new
28
36
  end
29
37
 
30
38
  def apply_decorators_pattern_to_path(path)
31
- path.join *pattern
39
+ path.join(*pattern)
32
40
  end
33
41
 
34
42
  def find_decorators_in_path(path)
35
43
  Dir[apply_decorators_pattern_to_path(path)]
36
44
  end
37
45
 
46
+ def load_decorator(decorator, cache_classes)
47
+ if cache_classes
48
+ require decorator
49
+ else
50
+ load decorator
51
+ end
52
+ end
53
+
54
+ # Decorators are loaded by hand, so Zeitwerk mustn't also manage them. Only
55
+ # subdirectories of app/decorators hold decorators; files directly inside it
56
+ # stay autoloadable.
57
+ def ignore_in_autoloader(path)
58
+ return unless defined?(Rails.autoloaders) && Rails.application && Rails.autoloaders.zeitwerk_enabled?
59
+
60
+ Dir[Pathname(path).join("app", "decorators", "*")].select { |entry| File.directory?(entry) }.each do |directory|
61
+ Rails.autoloaders.main.ignore(directory)
62
+ end
63
+ end
64
+
38
65
  def pattern
39
- ['app', 'decorators', '*', '**', '*_decorator.rb']
66
+ ["app", "decorators", "*", "**", "*_decorator.rb"]
40
67
  end
41
68
  end
42
-
43
69
  end
44
-
45
- require 'decorators/railtie'
data/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # Decorators Plugin [![Build Status](https://secure.travis-ci.org/parndt/decorators.png?branch=master)](http://travis-ci.org/parndt/decorators)
1
+ # Decorators Plugin
2
2
 
3
3
  This is a very simple plugin that adds support for decorators to your Rails application.
4
4
  Effectively all that this does is allow you to register paths in which to search
@@ -26,7 +26,7 @@ The important parts are being inside a sub directory of `app/decorators` and hav
26
26
  In your Gemfile, add the gem:
27
27
 
28
28
  ```ruby
29
- gem 'decorators', '~> 2.0.3'
29
+ gem 'decorators', '~> 2.1'
30
30
  ```
31
31
 
32
32
  Now, run `bundle install` and the gem should install.
@@ -49,6 +49,13 @@ require 'decorators'
49
49
  Decorators.register! Rails.root, Rails.root.join('vendor', 'extensions', 'extension_with_decorators')
50
50
  ```
51
51
 
52
+ #### Zeitwerk
53
+
54
+ Decorators loads these files itself, so it tells Zeitwerk to ignore the
55
+ subdirectories of `app/decorators` in every path you register. Register your
56
+ paths before eager loading happens, e.g. from an initializer or a `to_prepare`
57
+ block, not `after_initialize`.
58
+
52
59
  #### Avoiding Rails development mode reloading issues ([example](https://github.com/refinery/refinerycms/issues/2267))
53
60
 
54
61
  If you are loading this from within a Rails engine definition make sure you require
metadata CHANGED
@@ -1,40 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decorators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Arndt
8
- autorequire:
9
8
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z
14
- L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMTgxMDI5MDk0MjQ5WhcNMTkxMDI5MDk0
15
- MjQ5WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G
16
- CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQClF0/voptshDoTILFgUjvkViCOPe3W
17
- uuDwfSep+gc5AI83MmrmonN3L/dwm60D3HhZOtVt9el1n5E5b5aPzJngjdF9sFPX
18
- OIx3UlYde+WkzbG4iR2U0/8dMZ6DYuz6ijgPEpU1UKodUJVqEmt3Vc+rzDET9zoK
19
- TkIALNbSaV2G32ZDhoabeQJoJ0ce/2vjDqhM7awG7CYGRqRq4c0NOKKm0bGh+LOo
20
- vQNDvRjXPs0yp5i3keCgf6IcQ26nluqILYGPjuTExJj+k6AKfq6SPWDVtzSqdfiH
21
- STs/W85rwrKdLfEzfXxNsHvJ6Ryx+0A0hsNbfTTOhp4dkYm/6fyOejp7Of7qWRw/
22
- kJhI/PTq1gqh+Irpr+wUz04xItGE8WglKv1ydTUqBlCz2l9NfVTChtUpYlrk4FvN
23
- r7s6fcXH5cNX1ll2D1X2XLxmYEUgbAv5xApspvmpdRY5zlmSXZapi2KbW5iqpOV2
24
- luxRjhjfcOKfMugvGrMUFiqDaDi5IXS25KECAwEAAaNxMG8wCQYDVR0TBAIwADAL
25
- BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFLzeU7GH0rvnvDchSWtJhceiUDDTMBoGA1Ud
26
- EQQTMBGBD2dlbXNAcC5hcm5kdC5pbzAaBgNVHRIEEzARgQ9nZW1zQHAuYXJuZHQu
27
- aW8wDQYJKoZIhvcNAQELBQADggGBABMRA737G23Oiy1xBgVJsDW5LgGbeK9JQCC9
28
- eRdx22TDyrJ5vviqB22k13+zp/tq5fgeCsrk5iLAt5F/GgcP82p7pPm3qKi1QWip
29
- cnQvy5fLKcl+PaIX/+PYGVKUfV/wA+NuP06RSnzvNPepcUvbTJdAr6nQVdIh/ftB
30
- 64QhOWuk2CuGlt+tLMGbjR65W3SppBkvVd4yYHArbl4Z0qPG+TVrVrj2JEjo82rT
31
- jIUDLkdUlQ/FmH5fHhbrtn5PMCXjto414YBC7aQUxQsiNCN2qhsjwiyzVBbBTjnA
32
- 1sA043YnGOd1XylVtnrARK5eT7DhFGrMGMp/KvOg+T7q19+65jaopvHH4zFXzBcY
33
- MxlH/7tMQ5+DdHcqbu3SOAe1/VaaRk28J0CdPZS6Y60YuRqL17Zg2WOODiBkA9WE
34
- JjcyzdERZXsSPh+DT5PrllEbTNTZPbBcnAWjqdEWLtBIxD3JpgZHTmYP4I2ExAeu
35
- 2Oqsxsw30MIZnh2Cw/xLRkc1I50luA==
36
- -----END CERTIFICATE-----
37
- date: 2019-10-02 00:00:00.000000000 Z
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
38
11
  dependencies:
39
12
  - !ruby/object:Gem::Dependency
40
13
  name: railties
@@ -45,7 +18,7 @@ dependencies:
45
18
  version: 4.0.0
46
19
  - - "<"
47
20
  - !ruby/object:Gem::Version
48
- version: '7'
21
+ version: '9'
49
22
  type: :runtime
50
23
  prerelease: false
51
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -55,7 +28,7 @@ dependencies:
55
28
  version: 4.0.0
56
29
  - - "<"
57
30
  - !ruby/object:Gem::Version
58
- version: '7'
31
+ version: '9'
59
32
  - !ruby/object:Gem::Dependency
60
33
  name: rspec
61
34
  requirement: !ruby/object:Gem::Requirement
@@ -63,9 +36,6 @@ dependencies:
63
36
  - - ">="
64
37
  - !ruby/object:Gem::Version
65
38
  version: 3.5.0
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.5'
69
39
  type: :development
70
40
  prerelease: false
71
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -73,9 +43,6 @@ dependencies:
73
43
  - - ">="
74
44
  - !ruby/object:Gem::Version
75
45
  version: 3.5.0
76
- - - "~>"
77
- - !ruby/object:Gem::Version
78
- version: '3.5'
79
46
  description: Manages the process of loading decorators into your Rails application.
80
47
  email: gems@p.arndt.io
81
48
  executables: []
@@ -91,7 +58,6 @@ homepage: https://github.com/parndt/decorators
91
58
  licenses:
92
59
  - MIT
93
60
  metadata: {}
94
- post_install_message:
95
61
  rdoc_options: []
96
62
  require_paths:
97
63
  - lib
@@ -106,8 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
72
  - !ruby/object:Gem::Version
107
73
  version: '0'
108
74
  requirements: []
109
- rubygems_version: 3.0.3
110
- signing_key:
75
+ rubygems_version: 4.0.20
111
76
  specification_version: 4
112
77
  summary: Rails decorators plugin.
113
78
  test_files: []
checksums.yaml.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- f����{����{�oQ�z��c�?xW����C�� �Ѫ>�EjB���jr���\�۟�
2
- se�f 2m���`ER�K,��+|o��bՉD�@�h|���|6����o[O±?2�G�L� A9��L�;��w�?F㓬3���T �X��L6]Ao��E�k�ڀwӧ��_�ц�@�1�
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file