Module: BetterAuth::RequestState
- Defined in:
- lib/better_auth/request_state.rb
Defined Under Namespace
Classes: State
Constant Summary collapse
- THREAD_KEY =
:better_auth_request_state_stack
Class Method Summary collapse
- .current_store ⇒ Object
- .define(&initializer) ⇒ Object
- .present? ⇒ Boolean
- .run(store = {}, &block) ⇒ Object
- .stack ⇒ Object
Class Method Details
.current_store ⇒ Object
32 33 34 |
# File 'lib/better_auth/request_state.rb', line 32 def current_store stack.last || raise("No request state found. Please make sure you are calling this function within a `run` callback.") end |
.define(&initializer) ⇒ Object
36 37 38 |
# File 'lib/better_auth/request_state.rb', line 36 def define(&initializer) State.new(Object.new.freeze, initializer || -> {}) end |
.present? ⇒ Boolean
28 29 30 |
# File 'lib/better_auth/request_state.rb', line 28 def present? !stack.empty? end |
.run(store = {}, &block) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/better_auth/request_state.rb', line 21 def run(store = {}, &block) stack.push(store) block.call ensure stack.pop end |
.stack ⇒ Object
40 41 42 |
# File 'lib/better_auth/request_state.rb', line 40 def stack Thread.current[THREAD_KEY] ||= [] end |