Skip to content

Commit

Permalink
rename compiler mode to development mode
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhawksley committed Sep 10, 2024
1 parent a59419e commit 2b26f1b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions lib/view_component/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

module ViewComponent
class Compiler
# Compiler production mode. Can be either:
# * false (a blocking mode which ensures thread safety when redefining the `call` method for components,
# Compiler development mode. Can be either:
# * true (a blocking mode which ensures thread safety when redefining the `call` method for components,
# default in Rails development and test mode)
# * true(a non-blocking mode, default in Rails production mode)
class_attribute :production_mode, default: true
# * false(a non-blocking mode, default in Rails production mode)
class_attribute :development_mode, default: false

def initialize(component)
@component = component
Expand All @@ -26,7 +26,7 @@ def compile(raise_errors: false, force: false)

gather_templates

if !self.class.production_mode && @templates.none? { !(_1.inline_call? && !_1.defined_on_self?) }
if self.class.development_mode && @templates.none? { !(_1.inline_call? && !_1.defined_on_self?) }
@component.superclass.compile(raise_errors: raise_errors)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def serve_static_preview_assets?(app_config)
end

initializer "compiler mode" do |_app|
ViewComponent::Compiler.production_mode = !(Rails.env.development? || Rails.env.test?)
ViewComponent::Compiler.development_mode = (Rails.env.development? || Rails.env.test?)
end

config.after_initialize do |app|
Expand Down
6 changes: 3 additions & 3 deletions test/sandbox/test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def test_sets_the_compiler_mode_in_production_mode
Rails.env = "production".inquiry

ViewComponent::Engine.initializers.find { |i| i.name == "compiler mode" }.run
assert_equal true, ViewComponent::Compiler.production_mode
assert_equal false, ViewComponent::Compiler.development_mode
ensure
Rails.env = old_env
ViewComponent::Engine.initializers.find { |i| i.name == "compiler mode" }.run
Expand All @@ -680,12 +680,12 @@ def test_sets_the_compiler_mode_in_production_mode
def test_sets_the_compiler_mode_in_development_mode
Rails.env.stub :development?, true do
ViewComponent::Engine.initializers.find { |i| i.name == "compiler mode" }.run
assert_equal false, ViewComponent::Compiler.production_mode
assert_equal true, ViewComponent::Compiler.development_mode
end

Rails.env.stub :test?, true do
ViewComponent::Engine.initializers.find { |i| i.name == "compiler mode" }.run
assert_equal false, ViewComponent::Compiler.production_mode
assert_equal true, ViewComponent::Compiler.development_mode
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ def test_output_preamble_and_postamble
end

def test_compilation_in_development_mode
with_compiler_production_mode(false) do
with_compiler_development_mode(true) do
with_new_cache do
render_inline(MyComponent.new)
assert_selector("div", text: "hello,world!")
Expand All @@ -924,7 +924,7 @@ def test_compilation_in_development_mode
end

def test_compilation_in_production_mode
with_compiler_production_mode(true) do
with_compiler_development_mode(false) do
with_new_cache do
render_inline(MyComponent.new)
assert_selector("div", text: "hello,world!")
Expand All @@ -948,7 +948,7 @@ def test_multithread_render
end

def test_concurrency_deadlock_cache
with_compiler_production_mode(false) do
with_compiler_development_mode(true) do
with_new_cache do
render_inline(ContentEvalComponent.new) do
ViewComponent::CompileCache.invalidate!
Expand Down Expand Up @@ -1073,7 +1073,7 @@ def test_renders_nested_collection
end

def test_concurrency_deadlock
with_compiler_production_mode(false) do
with_compiler_development_mode(true) do
with_new_cache do
mutex = Mutex.new

Expand Down
8 changes: 4 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ def with_render_monkey_patch_config(enabled, &block)
with_config_option(:render_monkey_patch_enabled, enabled, &block)
end

def with_compiler_production_mode(mode)
previous_mode = ViewComponent::Compiler.production_mode
ViewComponent::Compiler.production_mode = mode
def with_compiler_development_mode(mode)
previous_mode = ViewComponent::Compiler.development_mode
ViewComponent::Compiler.development_mode = mode
yield
ensure
ViewComponent::Compiler.production_mode = previous_mode
ViewComponent::Compiler.development_mode = previous_mode
end

def capture_warnings(&block)
Expand Down

0 comments on commit 2b26f1b

Please sign in to comment.