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.
225 226 227 228 |
# File 'app/models/concerns/has_custom_fields.rb', line 225 def initialize(preloaded, klass_with_custom_fields) @preloaded = preloaded @klass_with_custom_fields = klass_with_custom_fields end |
Instance Method Details
#[](key) ⇒ Object
230 231 232 233 234 235 236 237 238 |
# File 'app/models/concerns/has_custom_fields.rb', line 230 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 |