Class: ActiveRecord::CachedValue
- Inherits:
-
ObjectProxy
- Object
- ObjectProxy
- ActiveRecord::CachedValue
- Defined in:
- lib/cached_value.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #find_target(skip_cache = false) ⇒ Object
-
#initialize(owner, reflection) ⇒ CachedValue
constructor
A new instance of CachedValue.
- #load(force_update = false) ⇒ Object
- #reload ⇒ Object (also: #update)
- #target ⇒ Object
Constructor Details
#initialize(owner, reflection) ⇒ CachedValue
Returns a new instance of CachedValue.
7 8 9 |
# File 'lib/cached_value.rb', line 7 def initialize(owner, reflection) @owner, @reflection = owner, reflection end |
Instance Method Details
#clear ⇒ Object
25 26 27 28 29 |
# File 'lib/cached_value.rb', line 25 def clear clear_cache @owner.instance_variable_set("@#{@reflection.name}", nil) self end |
#find_target(skip_cache = false) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/cached_value.rb', line 35 def find_target(skip_cache = false) target = find_target_from_cache unless skip_cache unless target target ||= @reflection.[:sql] ? find_target_by_sql : find_target_by_eval end target end |
#load(force_update = false) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/cached_value.rb', line 11 def load(force_update = false) @target = find_target force_update if force_update || (has_cache? && find_target_from_cache.nil?) update_cache @target end self end |
#reload ⇒ Object Also known as: update
19 20 21 |
# File 'lib/cached_value.rb', line 19 def reload @owner.send(@reflection.name).load(true) end |
#target ⇒ Object
31 32 33 |
# File 'lib/cached_value.rb', line 31 def target @target end |