Module: Cachely::ClassMethods
- Defined in:
- lib/cachely.rb
Instance Method Summary collapse
-
#cachely(fcn, opts = {}, &extension) ⇒ Array
Catches the method name, stores for after because methods aren’t loaded when this is called.
-
#method_added(name) ⇒ Object
Called after methods loaded, this aliases out the old method, puts in place the listener version That only calls it if the cache can’t fill in.
-
#singleton_method_added(name) ⇒ Object
Called after class methods loaded, this aliases out the old method, puts in place the listener version That only calls it if the cache can’t fill in.
Instance Method Details
#cachely(fcn, opts = {}, &extension) ⇒ Array
Catches the method name, stores for after because methods aren’t loaded when this is called.
47 48 49 50 51 52 53 |
# File 'lib/cachely.rb', line 47 def cachely(fcn, opts = {}, &extension) @cachely_fcns ||= [] @cachely_opts ||= {} @cachely_fcns << fcn @cachely_opts[fcn] = opts end |
#method_added(name) ⇒ Object
Called after methods loaded, this aliases out the old method, puts in place the listener version That only calls it if the cache can’t fill in.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cachely.rb', line 30 def method_added(name) if(@cachely_fcns and @cachely_fcns.include?(name) and !self.new.respond_to?("#{name.to_s}_old".to_sym)) # only do this if we either haven't explicitly labeled fcn type, or it's not class. unless(@cachely_opts[name][:type] and @cachely_opts[name][:type] == "class") self.class_eval("alias :#{"#{name.to_s}_old".to_sym} :#{name}") #alias old function out Cachely::Mechanics.setup_method(self,name, @cachely_opts[name][:time_to_expiry]) end end super end |
#singleton_method_added(name) ⇒ Object
Called after class methods loaded, this aliases out the old method, puts in place the listener version That only calls it if the cache can’t fill in.
15 16 17 18 19 20 21 22 23 |
# File 'lib/cachely.rb', line 15 def singleton_method_added(name) if(@cachely_fcns and @cachely_fcns.include?(name) and !self.respond_to?("#{name.to_s}_old".to_sym)) unless(@cachely_opts[name][:type] and @cachely_opts[name][:type] == "instance") self.instance_eval("alias :#{"#{name.to_s}_old".to_sym} :#{name}") Cachely::Mechanics.setup_method(self,name, @cachely_opts[name][:time_to_expiry], true) end end super end |