-
-
Save wesley6j/c088ea82b157a0ba1fa0183937083c68 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,33 @@ module Acts module Cacheable def self.included(base) base.extend(ClassMethods) end module ClassMethods def acts_as_cacheable(key, options = {}) extend Acts::Cacheable::SingletonMethods find(:all, options).each{|instance| cached_objects[instance.send(key).to_s] = instance} end end module SingletonMethods def [] (key) cached_objects[key] end def cached(id) cached_objects.each_value{|instance| return instance if instance.id == id} end def objects cached_objects.values end private def cached_objects @all_cached_objects ||= Hash.new end end end end -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,16 @@ module Acts module Cacheable def acts_as_cacheable(key, options = {}) find(:all, options).each{|instance| class_finders[instance.send(key).to_s] = instance} class_eval <<-EOF def self.[] (key) class_finders[key] end EOF end def class_finders @class_finders ||= Hash.new end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ class Person < ActiveRecord::Base acts_as_cacheable :login, :conditions => {:admin => true} end -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ module Acts module Cacheable def acts_as_cacheable(key, options = {}) validates_uniqueness_of key find(:all, options).each{|instance| class_finders[key][instance.send(key).to_s] = instance} class_eval <<-EOF def self.[] (key) class_finders[#{key.inspect}][key] end def self.cached(id) class_finders[#{key.inspect}].each_value{|instance| return instance if instance.id == id} end EOF end -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ module Acts module Cacheable def acts_as_cacheable(method, options = {}) validates_uniqueness_of method find(:all, options).each{|instance| class_finders[method][instance.send(method).to_s] = instance} class_eval <<-EOF def self.[] (key) class_finders[#{method.inspect}][key] end def self.cached(id) class_finders[#{method.inspect}].each_value{|instance| return instance if instance.id == id} end EOF end def class_finders @class_finders ||= Hash.new {|hash, key| hash[key] = {} } end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ class Unit < ActiveRecord::Base acts_as_cacheable :key end