<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/cached_value.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,2 +1,3 @@
+require 'cached_value'
 require 'cached_values'
-ActiveRecord::Base.send :include, HasCachedValueExtension
+ActiveRecord::Base.send :include, CachedValues</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -39,7 +39,7 @@ module CachedValues # :nodoc:
 
       configure_dependency_for_cached_value(reflection)
 
-      reflection.options[:cache] ||= reflection.name unless false == reflection.options[:counter_cache]
+      reflection.options[:cache] ||= reflection.name unless false == options[:cache]
 
       cached_value_accessor_method(reflection, ActiveRecord::CachedValue)
     end
@@ -80,118 +80,3 @@ module CachedValues # :nodoc:
       end
   end
 end
-
-module ActiveRecord
-  class CachedValue
-    attr_reader :reflection
-    instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$)/ }
-
-    def initialize(owner, reflection)
-      @owner, @reflection = owner, reflection
-      reset
-    end
-    
-    def reset
-      @target = nil
-      @loaded = false
-    end
-
-    def load
-      reset
-      load_target
-    end
-
-    def reload
-      reset
-      clear_cache
-      load_target
-    end
-    
-    def clear
-      clear_cache
-      @owner.instance_variable_set(&quot;@#{@reflection.name}&quot;, nil)
-    end
-
-    def loaded?
-      @loaded
-    end
-    
-    def loaded
-      @loaded = true
-    end
-    
-    def target
-      @target
-    end
-
-    protected
-      
-      def load_target
-        return nil unless defined?(@loaded)
-        @target = find_target unless loaded?
-        @loaded = true
-        @target
-      end
-
-      def find_target
-        target = find_target_from_cache
-        unless target
-          target ||= @reflection.options[:sql] ? find_target_by_sql : find_target_by_eval
-          update_cache(target)
-        end
-        target
-      end
-      
-      def find_target_from_cache
-        @owner.send(:read_attribute, cache_column) if has_cached_counter?
-      end
-      
-      def find_target_by_sql
-        @owner.class.count_by_sql(sanitize_sql(interpolate_sql(@reflection.options[:sql])))
-      end
-    
-      def find_target_by_eval
-        if @reflection.options[:eval].is_a?(String)
-          eval(@reflection.options[:eval], @owner.send(:binding))
-        elsif @reflection.options[:eval].is_a?(Proc)
-          @reflection.options[:eval].call(@owner)
-        else
-          raise ArgumentError.new(&quot;The :eval option on a cached_values must be either a String or a Proc&quot;)
-        end
-      end
-      
-      def cache_column
-        @reflection.options[:cache]
-      end
-
-      def has_cache?
-        @reflection.options[:cache] &amp;&amp; @owner.attribute_names.include?(@reflection.options[:cache].to_s)
-      end
-      
-      def clear_cache
-        update_cache(nil)
-      end
-      
-      def update_cache(value)
-        return unless has_cache?
-        unless @owner.new_record?
-          @owner.class.update_all([&quot;#{cache_column} = ?&quot;, value], [&quot;id = ?&quot;, @owner.id])
-        end
-        @owner.send(:write_attribute, cache_column, value)
-      end
-      
-      def interpolate_sql(sql, record = nil)
-        @owner.send(:interpolate_sql, sql, record)
-      end
-
-      def sanitize_sql(sql)
-        @owner.class.send(:sanitize_sql, sql)
-      end
-      
-      def method_missing(method, *args, &amp;block)
-        if load_target        
-          @target.send(method, *args, &amp;block)
-        end
-      end
-  end
-end</diff>
      <filename>lib/cached_values.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>72148ad1d259541dfb68e03fe479669c15fa91c0</id>
    </parent>
  </parents>
  <author>
    <name>studioda</name>
    <email>studioda@7491b73d-821b-0410-9297-ad1f6b5b4194</email>
  </author>
  <url>http://github.com/JackDanger/cached_values/commit/36fe5e1742b2e2e5b1bcb4e1445ba178b82d539b</url>
  <id>36fe5e1742b2e2e5b1bcb4e1445ba178b82d539b</id>
  <committed-date>2007-08-31T08:58:19-07:00</committed-date>
  <authored-date>2007-08-31T08:58:19-07:00</authored-date>
  <message>refactored the pieces apart

git-svn-id: http://svn.6brand.com/projects/plugins/cached_values@354 7491b73d-821b-0410-9297-ad1f6b5b4194</message>
  <tree>8f9f51588cdb206cb5ecde592c53085711add4dd</tree>
  <committer>
    <name>studioda</name>
    <email>studioda@7491b73d-821b-0410-9297-ad1f6b5b4194</email>
  </committer>
</commit>
