Class: StrictLazy::Facade
- Inherits:
-
Object
- Object
- StrictLazy::Facade
- Defined in:
- lib/strict_lazy/facade.rb
Overview
The .lazy namespace. Reading record.lazy.x resolves a declared lazy value without ever growing a bare x method on the record itself.
Read order:
1. +@_lazy_<reader>+ already set -> return it (resolved / eager / group-resolved)
2. +@_batch_<reader>+ present -> resolve the whole group once, return it
3. no batch and violation :raise -> UnloadedError (no wasted query)
4. no batch and non-strict -> degraded single-record resolve (fallback)
Instance Method Summary collapse
-
#initialize(record) ⇒ Facade
constructor
A new instance of Facade.
- #method_missing(name, *args) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(record) ⇒ Facade
Returns a new instance of Facade.
13 14 15 |
# File 'lib/strict_lazy/facade.rb', line 13 def initialize(record) @record = record end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/strict_lazy/facade.rb', line 21 def method_missing(name, *args) loader = loaders[name] return super unless loader return @record.instance_variable_get(loader.value_ivar) if @record.instance_variable_defined?(loader.value_ivar) batch = @record.instance_variable_get(loader.batch_ivar) return batch.value_for(@record) if batch unloaded(loader) end |
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
17 18 19 |
# File 'lib/strict_lazy/facade.rb', line 17 def respond_to_missing?(name, include_private = false) loaders.key?(name) || super end |