Class: Mongory::Utils::Context
- Inherits:
-
Object
- Object
- Mongory::Utils::Context
- Defined in:
- lib/mongory/utils/context.rb
Overview
Context is a utility class that provides a stable but mutatable shared context for the Mongory query builder. It holds the configuration and the current record being matcher tree processed.
Instance Attribute Summary collapse
-
#config ⇒ Config
The configuration object for the context.
-
#current_record ⇒ Record
The current record being processed in the matcher tree.
-
#need_convert ⇒ Boolean
Whether the record needs to be converted before matching.
Instance Method Summary collapse
-
#dup ⇒ Context
Creates a duplicate of the context with its own configuration.
-
#initialize(config = {}) ⇒ Context
constructor
Initializes a new Context instance with the given configuration.
Constructor Details
#initialize(config = {}) ⇒ Context
Initializes a new Context instance with the given configuration.
24 25 26 27 28 |
# File 'lib/mongory/utils/context.rb', line 24 def initialize(config = {}) @config = config @current_record = nil @need_convert = true end |
Instance Attribute Details
#config ⇒ Config
The configuration object for the context
17 18 19 |
# File 'lib/mongory/utils/context.rb', line 17 def config @config end |
#current_record ⇒ Record
The current record being processed in the matcher tree
17 18 19 |
# File 'lib/mongory/utils/context.rb', line 17 def current_record @current_record end |
#need_convert ⇒ Boolean
Whether the record needs to be converted before matching
17 18 19 |
# File 'lib/mongory/utils/context.rb', line 17 def need_convert @need_convert end |
Instance Method Details
#dup ⇒ Context
The new context shares the same configuration object but has its own state
Creates a duplicate of the context with its own configuration.
34 35 36 37 38 |
# File 'lib/mongory/utils/context.rb', line 34 def dup new_context = super new_context.config = @config.dup new_context end |