Class: Cuprum::Rails::Actions::Middleware::Associations::Cache
- Inherits:
-
Command
- Object
- Command
- Cuprum::Rails::Actions::Middleware::Associations::Cache
- Defined in:
- lib/cuprum/rails/actions/middleware/associations/cache.rb
Overview
Pre-warm the association cache for a resource.
Constant Summary collapse
- ACTIVE_RECORD_STRATEGY =
Strategy for caching an association value on an ActiveRecord model.
lambda do |entity:, name:, value:| entity.send(:association_instance_set, name, value) entity end
- DEFAULT_STRATEGY =
Generic strategy for caching an association value.
lambda do |entity:, name:, value:| entity[name] = value entity end
Instance Attribute Summary collapse
-
#association ⇒ Cuprum::Associations::Association
readonly
The association to cache.
-
#resource ⇒ Cuprum::Rails::Resource
readonly
The resource to cache.
Class Method Summary collapse
-
.define_strategy(klass) {|entity, name, value| ... } ⇒ Object
Defines a strategy for caching an association value.
-
.strategies ⇒ Proc
The defined strategies for caching association values.
Instance Method Summary collapse
-
#initialize(association:, resource:) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(association:, resource:) ⇒ Cache
Returns a new instance of Cache.
53 54 55 56 57 58 |
# File 'lib/cuprum/rails/actions/middleware/associations/cache.rb', line 53 def initialize(association:, resource:) super() @association = association @resource = resource end |
Instance Attribute Details
#association ⇒ Cuprum::Associations::Association (readonly)
Returns the association to cache.
61 62 63 |
# File 'lib/cuprum/rails/actions/middleware/associations/cache.rb', line 61 def association @association end |
#resource ⇒ Cuprum::Rails::Resource (readonly)
Returns the resource to cache.
64 65 66 |
# File 'lib/cuprum/rails/actions/middleware/associations/cache.rb', line 64 def resource @resource end |
Class Method Details
.define_strategy(klass) {|entity, name, value| ... } ⇒ Object
Defines a strategy for caching an association value.
40 41 42 |
# File 'lib/cuprum/rails/actions/middleware/associations/cache.rb', line 40 def define_strategy(klass, &block) (@strategies ||= STRATEGIES.dup)[klass] = block end |
.strategies ⇒ Proc
Returns the defined strategies for caching association values.
45 46 47 |
# File 'lib/cuprum/rails/actions/middleware/associations/cache.rb', line 45 def strategies (@strategies ||= STRATEGIES.dup).reverse_each end |