view_component 2.63.0 → 2.64.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of view_component might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78c8a36fb19eb4c8a1c3737815113323acc9cd5a9c89a270163ca8336e44c41e
4
- data.tar.gz: 6e4135faf54dfc7c519d7ef62080d6e779d04bbbc1efea32b7871fe65bd2c685
3
+ metadata.gz: 1cee1c1b53cec5fec9d4613416a27999c653c2cf8fb176798b235c7b71dc795d
4
+ data.tar.gz: 5fb8a364788849fecfb8bb2160ebd6dc403f624ba6b3fe13c818706f928b8257
5
5
  SHA512:
6
- metadata.gz: 0f207e3d9e6980880876afa36521a3f63abafead81da8d4f5574c9e9164139fbd8029bf8b9eae3f034e2da849541b959025612b21dca548477a38327fe5aa97b
7
- data.tar.gz: d65662034f4abf33feeae814b60dcfb82683302be1cf427a5c6f93297a575185963ca8d3a1df81fa9daf7855d25297c303c68e5abc225594be842e12fd657702
6
+ metadata.gz: d721f8d07af64e314a506afc364941f95d3b824d27e587e12d8c774f4fa168b7ae00ac400c4f73b546ed0d5728aec60d586e52dacaee2b8f10e01230bbe3ab8f
7
+ data.tar.gz: 598ab2f08524a8eb10b17a001ed7429223ca39ab204c25cec4375ea201e3afa1c852ba1578f81a1de5c83211e1eb05f3c1a7d146f83cc1d77e3f4ed0bfdef962
data/docs/CHANGELOG.md CHANGED
@@ -9,6 +9,30 @@ title: Changelog
9
9
 
10
10
  ## main
11
11
 
12
+ ## 2.64.0
13
+
14
+ * Add `warn_on_deprecated_slot_setter` flag to opt-in to deprecation warning.
15
+
16
+ In [v2.54.0](https://viewcomponent.org/CHANGELOG.html#2540), the Slots API was updated to require the `with_*` prefix for setting Slots. The non-`with_*` setters will be deprecated in a coming version and removed in `v3.0`.
17
+
18
+ To enable the coming deprecation warning, add `warn_on_deprecated_slot_setter`:
19
+
20
+ ```ruby
21
+ class DeprecatedSlotsSetterComponent < ViewComponent::Base
22
+ warn_on_deprecated_slot_setter
23
+ end
24
+ ```
25
+
26
+ *Joel Hawksley*
27
+
28
+ * Add [`m`](https://rubygems.org/gems/m) to development environment.
29
+
30
+ *Joel Hawksley*
31
+
32
+ * Fix potential deadlock scenario in the compiler's development mode.
33
+
34
+ *Blake Williams*
35
+
12
36
  ## 2.63.0
13
37
 
14
38
  * Fixed typo in `renders_many` documentation.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "concurrent-ruby"
4
+
3
5
  module ViewComponent
4
6
  class Compiler
5
7
  # Lock required to be obtained before compiling the component
@@ -16,7 +18,7 @@ module ViewComponent
16
18
 
17
19
  def initialize(component_class)
18
20
  @component_class = component_class
19
- @__vc_compiler_lock = Monitor.new
21
+ @__vc_compiler_lock = Concurrent::ReadWriteLock.new
20
22
  end
21
23
 
22
24
  def compiled?
@@ -33,7 +35,7 @@ module ViewComponent
33
35
 
34
36
  component_class.superclass.compile(raise_errors: raise_errors) if should_compile_superclass?
35
37
 
36
- with_lock do
38
+ with_write_lock do
37
39
  CompileCache.invalidate_class!(component_class)
38
40
 
39
41
  subclass_instance_methods = component_class.instance_methods(false)
@@ -90,14 +92,18 @@ module ViewComponent
90
92
  end
91
93
  end
92
94
 
93
- def with_lock(&block)
95
+ def with_write_lock(&block)
94
96
  if development?
95
- __vc_compiler_lock.synchronize(&block)
97
+ __vc_compiler_lock.with_write_lock(&block)
96
98
  else
97
99
  block.call
98
100
  end
99
101
  end
100
102
 
103
+ def with_read_lock(&block)
104
+ __vc_compiler_lock.with_read_lock(&block)
105
+ end
106
+
101
107
  private
102
108
 
103
109
  attr_reader :component_class
@@ -123,7 +129,7 @@ module ViewComponent
123
129
  if development?
124
130
  component_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
125
131
  def render_template_for(variant = nil)
126
- self.class.compiler.with_lock do
132
+ self.class.compiler.with_read_lock do
127
133
  #{body}
128
134
  end
129
135
  end
@@ -61,10 +61,12 @@ module ViewComponent
61
61
  end
62
62
 
63
63
  define_method(setter_name) do |*args, &block|
64
- ViewComponent::Deprecation.warn(
65
- "polymorphic slot setters like `#{setter_name}` are deprecated and will be removed in " \
66
- "ViewComponent v3.0.0.\n\nUse `with_#{setter_name}` instead."
67
- )
64
+ if _warn_on_deprecated_slot_setter
65
+ ViewComponent::Deprecation.warn(
66
+ "polymorphic slot setters like `#{setter_name}` are deprecated and will be removed in " \
67
+ "ViewComponent v3.0.0.\n\nUse `with_#{setter_name}` instead."
68
+ )
69
+ end
68
70
 
69
71
  set_polymorphic_slot(slot_name, poly_type, *args, &block)
70
72
  end
@@ -17,9 +17,19 @@ module ViewComponent
17
17
  # Hash of registered Slots
18
18
  class_attribute :registered_slots
19
19
  self.registered_slots = {}
20
+
21
+ class_attribute :_warn_on_deprecated_slot_setter
22
+ self._warn_on_deprecated_slot_setter = false
20
23
  end
21
24
 
22
25
  class_methods do
26
+ ##
27
+ # Enables deprecations coming to the Slots API in ViewComponent v3
28
+ #
29
+ def warn_on_deprecated_slot_setter
30
+ self._warn_on_deprecated_slot_setter = true
31
+ end
32
+
23
33
  ##
24
34
  # Registers a sub-component
25
35
  #
@@ -80,7 +90,13 @@ module ViewComponent
80
90
  if args.empty? && block.nil?
81
91
  get_slot(slot_name)
82
92
  else
83
- # Deprecated: Will remove in 3.0
93
+ if _warn_on_deprecated_slot_setter
94
+ ViewComponent::Deprecation.warn(
95
+ "Setting a slot with `##{slot_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
96
+ "Use `#with_#{slot_name}` to set the slot instead."
97
+ )
98
+ end
99
+
84
100
  set_slot(slot_name, nil, *args, &block)
85
101
  end
86
102
  end
@@ -138,9 +154,15 @@ module ViewComponent
138
154
  # Define setter for singular names
139
155
  # for example `renders_many :items` allows fetching all tabs with
140
156
  # `component.tabs` and setting a tab with `component.tab`
141
- #
142
- # Deprecated: Will remove in 3.0
157
+
143
158
  define_method singular_name do |*args, &block|
159
+ if _warn_on_deprecated_slot_setter
160
+ ViewComponent::Deprecation.warn(
161
+ "Setting a slot with `##{singular_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
162
+ "Use `#with_#{singular_name}` to set the slot instead."
163
+ )
164
+ end
165
+
144
166
  set_slot(slot_name, nil, *args, &block)
145
167
  end
146
168
  ruby2_keywords(singular_name.to_sym) if respond_to?(:ruby2_keywords, true)
@@ -162,7 +184,13 @@ module ViewComponent
162
184
  if collection_args.nil? && block.nil?
163
185
  get_slot(slot_name)
164
186
  else
165
- # Deprecated: Will remove in 3.0
187
+ if _warn_on_deprecated_slot_setter
188
+ ViewComponent::Deprecation.warn(
189
+ "Setting a slot with `##{slot_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
190
+ "Use `#with_#{slot_name}` to set the slot instead."
191
+ )
192
+ end
193
+
166
194
  collection_args.map do |args|
167
195
  set_slot(slot_name, nil, **args, &block)
168
196
  end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 63
6
+ MINOR = 64
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.63.0
4
+ version: 2.64.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: concurrent-ruby
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: appraisal
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +156,20 @@ dependencies:
142
156
  - - "~>"
143
157
  - !ruby/object:Gem::Version
144
158
  version: '2'
159
+ - !ruby/object:Gem::Dependency
160
+ name: m
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '1'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '1'
145
173
  - !ruby/object:Gem::Dependency
146
174
  name: minitest
147
175
  requirement: !ruby/object:Gem::Requirement