Module: ViewComponentDevtools::State
- Defined in:
- lib/view_component_devtools/state.rb
Defined Under Namespace
Classes: Session
Constant Summary collapse
- KEY =
:view_component_devtools_session
Class Method Summary collapse
- .active? ⇒ Boolean
- .current ⇒ Object
- .reset! ⇒ Object
- .start!(request_id: nil) ⇒ Object
- .with_component(metadata) ⇒ Object
Class Method Details
.active? ⇒ Boolean
28 29 30 |
# File 'lib/view_component_devtools/state.rb', line 28 def active? !current.nil? end |
.current ⇒ Object
24 25 26 |
# File 'lib/view_component_devtools/state.rb', line 24 def current ActiveSupport::IsolatedExecutionState[KEY] end |
.reset! ⇒ Object
32 33 34 |
# File 'lib/view_component_devtools/state.rb', line 32 def reset! ActiveSupport::IsolatedExecutionState.delete(KEY) end |
.start!(request_id: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/view_component_devtools/state.rb', line 12 def start!(request_id: nil) unless ViewComponentDevtools.development_environment? raise "ViewComponent DevTools state can only start in development" end raise "ViewComponent DevTools capture already active" if active? ActiveSupport::IsolatedExecutionState[KEY] = Session.new( request_id: request_id || SecureRandom.uuid, configuration: ViewComponentDevtools.configuration ) end |
.with_component(metadata) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/view_component_devtools/state.rb', line 36 def with_component() return yield unless current current.push_component() yield ensure current&.pop_component() end |