Sha256: 6d25a56fc2117e8ffbcb8b1148861ab584eda03d22beb603a872569a69508591
Contents?: true
Size: 880 Bytes
Versions: 3
Compression:
Stored size: 880 Bytes
Contents
require 'active_support' require 'active_record' module ActiveRecord module LawnchairExtension def self.included(base) base.extend(ClassMethods) end module ClassMethods def lawnchair_cache(method, options={}) self.class_eval %{ def #{method}_with_lawnchair(*args) ident = lambda { |obj| obj.class.respond_to?(:primary_key) ? obj.send(obj.class.primary_key) : obj.to_s } arg_keys = args.map(&ident).join(':') key = "#\{self.class.name\}:#{method}:#\{ident.call(self)\}:#\{arg_keys\}" Lawnchair.cache(key, #{options.inspect}) do self.#{method}_without_lawnchair(*args) end end } alias_method_chain method, :lawnchair end end end end ActiveRecord::Base.class_eval do include ActiveRecord::LawnchairExtension end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lawnchair-0.6.11 | lib/active_record_extension.rb |
lawnchair-0.6.10 | lib/active_record_extension.rb |
lawnchair-0.6.9 | lib/active_record_extension.rb |