Class: HasCustomFields::PreloadedProxy
- Inherits:
-
Object
- Object
- HasCustomFields::PreloadedProxy
- Defined in:
- app/models/concerns/has_custom_fields.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(preloaded, klass_with_custom_fields) ⇒ PreloadedProxy
constructor
A new instance of PreloadedProxy.
Constructor Details
#initialize(preloaded, klass_with_custom_fields) ⇒ PreloadedProxy
Returns a new instance of PreloadedProxy.
193 194 195 196 |
# File 'app/models/concerns/has_custom_fields.rb', line 193 def initialize(preloaded, klass_with_custom_fields) @preloaded = preloaded @klass_with_custom_fields = klass_with_custom_fields end |
Instance Method Details
#[](key) ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'app/models/concerns/has_custom_fields.rb', line 198 def [](key) if @preloaded.key?(key) @preloaded[key] else # for now you can not mix preload an non preload, it better just to fail raise NotPreloadedError, "Attempted to access the non preloaded custom field '#{key}' on the '#{@klass_with_custom_fields}' class. This is disallowed to prevent N+1 queries." end end |