view_component_devtools 0.1.5 → 0.1.6

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: 19e386134c229033a8b5a19ddc40599a71e146f3ed19056704262b1da56c7774
4
- data.tar.gz: 8b52c866c56369924093515b39798425d61e4f7d2f6df91d19567fd6e89c4269
3
+ metadata.gz: 6d5ebb0adeb3fc06e01d4314298bf053e7374116ad151f93b4f26a0b45effef3
4
+ data.tar.gz: 716644f07896916f726dd42ef7908998896209e00045a459e9943c782a962ad0
5
5
  SHA512:
6
- metadata.gz: e236ec11c5296b69b50a7086e8275d71bbdc75859c3ddd676eaa3a6bc113f9440708ae8d022f8cb7fd9fa0a6caa17eb57d8a844b7fbebdf3a91e09a99441fd49
7
- data.tar.gz: 695b37d5553ea92efc1c75d97d95cc45dd19f32f4496105c8eedfc0844f09659848d88983a1784b0be531ff7b4a3fa2ec075b492682539b845f9001b9ec3048b
6
+ metadata.gz: 28e32d5d480906e613e9aa6fd330e8d3a6a2d59f87d955cd047fa6b3d00880c7dfafc0efd25f25f14697cee25e23e5582fbbee5b91b4b7bad0b8ea3c0cd1cbaf
7
+ data.tar.gz: 9c2adc18f06c16d29961921f37a3c9ec3cce8afc9172b336697b65cc28562e8801578319f4649c2a9387f7237a1e63c241601cc8bad869aab6b1fd4dbd510e3c
@@ -13,8 +13,7 @@ module ViewComponentDevtools
13
13
  /token/i
14
14
  ].freeze
15
15
 
16
- attr_accessor :allow_non_development,
17
- :enabled,
16
+ attr_accessor :enabled,
18
17
  :max_collection_size,
19
18
  :max_depth,
20
19
  :max_string_length,
@@ -22,7 +21,6 @@ module ViewComponentDevtools
22
21
 
23
22
  def initialize
24
23
  @enabled = false
25
- @allow_non_development = false
26
24
  @max_depth = 8
27
25
  @max_collection_size = 50
28
26
  @max_string_length = 2_000
@@ -30,7 +28,7 @@ module ViewComponentDevtools
30
28
  end
31
29
 
32
30
  def enabled_for?(environment)
33
- enabled && (environment.to_s == "development" || allow_non_development)
31
+ enabled && environment.to_s == "development"
34
32
  end
35
33
  end
36
34
  end
@@ -5,18 +5,25 @@ require "rails/engine"
5
5
  module ViewComponentDevtools
6
6
  class Engine < ::Rails::Engine
7
7
  initializer "view_component_devtools.middleware" do |application|
8
+ next unless ViewComponentDevtools.development_environment?
9
+
8
10
  application.middleware.use Middleware
9
11
  end
10
12
 
11
13
  initializer "view_component_devtools.helper" do
14
+ next unless ViewComponentDevtools.development_environment?
15
+
12
16
  ActiveSupport.on_load(:action_view) { include Helper }
13
17
  end
14
18
 
15
19
  initializer "view_component_devtools.subscriber" do
20
+ next unless ViewComponentDevtools.development_environment?
21
+
16
22
  Subscriber.install!
17
23
  end
18
24
 
19
25
  config.after_initialize do
26
+ ViewComponentDevtools.validate_environment!
20
27
  next unless ViewComponentDevtools.capture_enabled?
21
28
 
22
29
  Rails.application.config.view_component.instrumentation_enabled = true
@@ -10,6 +10,9 @@ module ViewComponentDevtools
10
10
 
11
11
  class << self
12
12
  def start!(request_id: nil)
13
+ unless ViewComponentDevtools.development_environment?
14
+ raise "ViewComponent DevTools state can only start in development"
15
+ end
13
16
  raise "ViewComponent DevTools capture already active" if active?
14
17
 
15
18
  ActiveSupport::IsolatedExecutionState[KEY] = Session.new(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentDevtools
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
@@ -19,6 +19,16 @@ module ViewComponentDevtools
19
19
  configuration.enabled_for?(environment)
20
20
  end
21
21
 
22
+ def development_environment?(environment = rails_environment)
23
+ environment.to_s == "development"
24
+ end
25
+
26
+ def validate_environment!(environment = rails_environment)
27
+ return unless configuration.enabled && !development_environment?(environment)
28
+
29
+ raise "ViewComponent DevTools can only be enabled in development"
30
+ end
31
+
22
32
  private
23
33
 
24
34
  def rails_environment
@@ -27,10 +37,12 @@ module ViewComponentDevtools
27
37
  end
28
38
  end
29
39
 
30
- require_relative "view_component_devtools/normalizer"
31
- require_relative "view_component_devtools/state"
32
- require_relative "view_component_devtools/component"
33
- require_relative "view_component_devtools/subscriber"
34
- require_relative "view_component_devtools/middleware"
35
- require_relative "view_component_devtools/helper"
40
+ if ViewComponentDevtools.development_environment?
41
+ require_relative "view_component_devtools/normalizer"
42
+ require_relative "view_component_devtools/state"
43
+ require_relative "view_component_devtools/component"
44
+ require_relative "view_component_devtools/subscriber"
45
+ require_relative "view_component_devtools/middleware"
46
+ require_relative "view_component_devtools/helper"
47
+ end
36
48
  require_relative "view_component_devtools/engine"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_devtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent DevTools contributors