view_component 2.45.0 → 2.46.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.

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: a209f06f513d226dba5ddcfefe8c08d16f84da6d8664fd9a4f2f70fe1ef48d96
4
- data.tar.gz: cc11c7e358b6fa3b07474a257202be93b0283c7c6189ce8d939770a805a28ef6
3
+ metadata.gz: b9b1ca38d53b64e55ff434c43f11839cf122d82d17768c2f064e2622ef88dc88
4
+ data.tar.gz: 7bc10806de04abbe6c7458305592d09ea6f4dfe9d86aff5d0cf0b9b9cfa9a620
5
5
  SHA512:
6
- metadata.gz: 2420eadefc54d1045c432b7b53010281bd923b556b72d4ed924b49a0a88b1841800d6e04f25bb043913f5c648693d19ad56117e441c838e7eb09e0ab5cf21315
7
- data.tar.gz: 4deb4c925810fcc2e3918e8735dd957003536e5533289d48caf69100dcb5ed58af6bb7af88fdc0cdf3c73e9905bb0222de18d9fd6cba65ca05e6bc3ed1f9964f
6
+ metadata.gz: 5c100fe77483f4b5f7227a47188f63428cbde65ebddf75cd0accf881d2140536150ea1d52f5c68b66126dd5087d9ac7fd7725f4c829a82d58c5cf86ef8abff2e
7
+ data.tar.gz: 19e3230c2b894651462dd6dbae44b4579267cc662c962e2bf9208e28cea299e01286427ae3c949d5622e8302cad4ba2b8f5e58a6aa6dabd3e872de367affb8bb
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- <img src="/docs/logo/github-readme-logo.svg" alt="ViewComponent logo" width="400">
1
+ ![ViewComponent logo](/docs/logo/readme-light.svg#gh-light-mode-only)
2
+ ![ViewComponent logo](/docs/logo/readme-dark.svg#gh-dark-mode-only)
2
3
 
3
4
  A framework for building reusable, testable & encapsulated view components in Ruby on Rails.
4
5
 
data/docs/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ title: Changelog
7
7
 
8
8
  ## main
9
9
 
10
+ ## 2.46.0
11
+
12
+ * Add thread safety to the compiler.
13
+
14
+ *Horia Radu*
15
+
16
+ * Add theme-specific logo images to readme.
17
+
18
+ *Dylan Smith*
19
+
20
+ * Add Orbit to users list.
21
+
22
+ *Nicolas Goutay*
23
+
24
+ * Increase clarity around purpose and use of slots.
25
+
26
+ *Simon Fish*
27
+
10
28
  ## 2.45.0
11
29
 
12
30
  * Remove internal APIs from API documentation, fix link to license.
@@ -45,6 +63,10 @@ title: Changelog
45
63
 
46
64
  *Yoshiyuki Hirano*
47
65
 
66
+ * Deprecate engine loading manually.
67
+
68
+ *Yoshiyuki Hirano*
69
+
48
70
  ## 2.44.0
49
71
 
50
72
  * Rename internal accessor to use private naming.
@@ -18,6 +18,10 @@ module ViewComponent
18
18
  cache.include? klass
19
19
  end
20
20
 
21
+ def invalidate_class!(klass)
22
+ cache.delete(klass)
23
+ end
24
+
21
25
  def invalidate!
22
26
  cache.clear
23
27
  end
@@ -2,8 +2,12 @@
2
2
 
3
3
  module ViewComponent
4
4
  class Compiler
5
+ # Lock required to be obtained before compiling the component
6
+ attr_reader :__vc_compiler_lock
7
+
5
8
  def initialize(component_class)
6
9
  @component_class = component_class
10
+ @__vc_compiler_lock = Monitor.new
7
11
  end
8
12
 
9
13
  def compiled?
@@ -13,55 +17,59 @@ module ViewComponent
13
17
  def compile(raise_errors: false)
14
18
  return if compiled?
15
19
 
16
- subclass_instance_methods = component_class.instance_methods(false)
20
+ __vc_compiler_lock.synchronize do
21
+ CompileCache.invalidate_class!(component_class)
17
22
 
18
- if subclass_instance_methods.include?(:with_content) && raise_errors
19
- raise ViewComponent::ComponentError.new(
20
- "#{component_class} implements a reserved method, `#with_content`.\n\n" \
21
- "To fix this issue, change the name of the method."
22
- )
23
- end
23
+ subclass_instance_methods = component_class.instance_methods(false)
24
24
 
25
- if template_errors.present?
26
- raise ViewComponent::TemplateError.new(template_errors) if raise_errors
27
-
28
- return false
29
- end
25
+ if subclass_instance_methods.include?(:with_content) && raise_errors
26
+ raise ViewComponent::ComponentError.new(
27
+ "#{component_class} implements a reserved method, `#with_content`.\n\n" \
28
+ "To fix this issue, change the name of the method."
29
+ )
30
+ end
30
31
 
31
- if subclass_instance_methods.include?(:before_render_check)
32
- ActiveSupport::Deprecation.warn(
33
- "`#before_render_check` will be removed in v3.0.0.\n\n" \
34
- "To fix this issue, use `#before_render` instead."
35
- )
36
- end
32
+ if template_errors.present?
33
+ raise ViewComponent::TemplateError.new(template_errors) if raise_errors
37
34
 
38
- if raise_errors
39
- component_class.validate_initialization_parameters!
40
- component_class.validate_collection_parameter!
41
- end
35
+ return false
36
+ end
42
37
 
43
- templates.each do |template|
44
- # Remove existing compiled template methods,
45
- # as Ruby warns when redefining a method.
46
- method_name = call_method_name(template[:variant])
38
+ if subclass_instance_methods.include?(:before_render_check)
39
+ ActiveSupport::Deprecation.warn(
40
+ "`#before_render_check` will be removed in v3.0.0.\n\n" \
41
+ "To fix this issue, use `#before_render` instead."
42
+ )
43
+ end
47
44
 
48
- if component_class.instance_methods.include?(method_name.to_sym)
49
- component_class.send(:undef_method, method_name.to_sym)
45
+ if raise_errors
46
+ component_class.validate_initialization_parameters!
47
+ component_class.validate_collection_parameter!
50
48
  end
51
49
 
52
- component_class.class_eval <<-RUBY, template[:path], -1
53
- def #{method_name}
54
- @output_buffer = ActionView::OutputBuffer.new
55
- #{compiled_template(template[:path])}
50
+ templates.each do |template|
51
+ # Remove existing compiled template methods,
52
+ # as Ruby warns when redefining a method.
53
+ method_name = call_method_name(template[:variant])
54
+
55
+ if component_class.instance_methods.include?(method_name.to_sym)
56
+ component_class.send(:undef_method, method_name.to_sym)
56
57
  end
57
- RUBY
58
- end
59
58
 
60
- define_render_template_for
59
+ component_class.class_eval <<-RUBY, template[:path], -1
60
+ def #{method_name}
61
+ @output_buffer = ActionView::OutputBuffer.new
62
+ #{compiled_template(template[:path])}
63
+ end
64
+ RUBY
65
+ end
66
+
67
+ define_render_template_for
61
68
 
62
- component_class._after_compile
69
+ component_class._after_compile
63
70
 
64
- CompileCache.register(component_class)
71
+ CompileCache.register(component_class)
72
+ end
65
73
  end
66
74
 
67
75
  private
@@ -145,6 +145,13 @@ module ViewComponent
145
145
  end
146
146
  end
147
147
 
148
- # In the case of automatic loading, "view_component" is loaded first,
149
- # so there is no need to load it.
150
- require "view_component" unless defined?(ViewComponent::Base)
148
+ # :nocov:
149
+ unless defined?(ViewComponent::Base)
150
+ ActiveSupport::Deprecation.warn(
151
+ "This manually engine loading is deprecated and will be removed in v3.0.0. " \
152
+ "Remove `require \"view_component/engine\"`."
153
+ )
154
+
155
+ require "view_component"
156
+ end
157
+ # :nocov:
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 45
6
+ MINOR = 46
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
@@ -19,6 +19,13 @@ module ViewComponent
19
19
  autoload :Translatable
20
20
  end
21
21
 
22
- # In the case of manually loading, "view_component/engine" is loaded first,
23
- # so there is no need to load it.
24
- require "view_component/engine" if defined?(Rails::Engine) && !defined?(ViewComponent::Engine)
22
+ # :nocov:
23
+ if defined?(ViewComponent::Engine)
24
+ ActiveSupport::Deprecation.warn(
25
+ "This manually engine loading is deprecated and will be removed in v3.0.0. " \
26
+ "Remove `require \"view_component/engine\"`."
27
+ )
28
+ elsif defined?(Rails::Engine)
29
+ require "view_component/engine"
30
+ end
31
+ # :nocov:
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.45.0
4
+ version: 2.46.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: 2021-11-23 00:00:00.000000000 Z
11
+ date: 2021-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport