0
@@ -39,7 +39,7 @@ module CachedValues # :nodoc:
0
configure_dependency_for_cached_value(reflection)
0
- reflection.options[:cache] ||= reflection.name unless false ==
reflection.options[:counter_cache]
0
+ reflection.options[:cache] ||= reflection.name unless false ==
options[:cache]
0
cached_value_accessor_method(reflection, ActiveRecord::CachedValue)
0
@@ -80,118 +80,3 @@ module CachedValues # :nodoc:
0
- attr_reader :reflection
0
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$)/ }
0
- def initialize(owner, reflection)
0
- @owner, @reflection = owner, reflection
0
- @owner.instance_variable_set("@#{@reflection.name}", nil)
0
- return nil unless defined?(@loaded)
0
- @target = find_target unless loaded?
0
- target = find_target_from_cache
0
- target ||= @reflection.options[:sql] ? find_target_by_sql : find_target_by_eval
0
- def find_target_from_cache
0
- @owner.send(:read_attribute, cache_column) if has_cached_counter?
0
- def find_target_by_sql
0
- @owner.class.count_by_sql(sanitize_sql(interpolate_sql(@reflection.options[:sql])))
0
- def find_target_by_eval
0
- if @reflection.options[:eval].is_a?(String)
0
- eval(@reflection.options[:eval], @owner.send(:binding))
0
- elsif @reflection.options[:eval].is_a?(Proc)
0
- @reflection.options[:eval].call(@owner)
0
- raise ArgumentError.new("The :eval option on a cached_values must be either a String or a Proc")
0
- @reflection.options[:cache]
0
- @reflection.options[:cache] && @owner.attribute_names.include?(@reflection.options[:cache].to_s)
0
- def update_cache(value)
0
- return unless has_cache?
0
- unless @owner.new_record?
0
- @owner.class.update_all(["#{cache_column} = ?", value], ["id = ?", @owner.id])
0
- @owner.send(:write_attribute, cache_column, value)
0
- def interpolate_sql(sql, record = nil)
0
- @owner.send(:interpolate_sql, sql, record)
0
- @owner.class.send(:sanitize_sql, sql)
0
- def method_missing(method, *args, &block)
0
- @target.send(method, *args, &block)
Comments
No one has commented yet.