Module: Aequitas::Context
- Defined in:
- lib/aequitas/context.rb
Class Method Summary collapse
-
.any?(&block) ⇒ Boolean
Are there any contexts on the stack?.
-
.current ⇒ Symbol, NilClass
Get the current validation context or nil (if no context is on the stack).
-
.in_context(context) ⇒ Object
Execute a block of code within a specific validation context.
-
.stack ⇒ Object
private
The (thread-local) validation context stack This allows object graphs to be saved within potentially nested contexts without having to pass the validation context throughout.
Class Method Details
.any?(&block) ⇒ Boolean
Are there any contexts on the stack?
39 40 41 |
# File 'lib/aequitas/context.rb', line 39 def self.any?(&block) stack.any?(&block) end |
.current ⇒ Symbol, NilClass
Get the current validation context or nil (if no context is on the stack).
29 30 31 |
# File 'lib/aequitas/context.rb', line 29 def self.current stack.last end |
.in_context(context) ⇒ Object
Execute a block of code within a specific validation context
16 17 18 19 20 21 22 |
# File 'lib/aequitas/context.rb', line 16 def self.in_context(context) stack << context return_value = yield ensure stack.pop return_value end |
.stack ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The (thread-local) validation context stack This allows object graphs to be saved within potentially nested contexts without having to pass the validation context throughout
48 49 50 |
# File 'lib/aequitas/context.rb', line 48 def self.stack Thread.current[:dm_validations_context_stack] ||= [] end |