Module: Cache::Object::ActiveRecord::ClassMethods
- Defined in:
- lib/cache/object/active_record.rb
Instance Method Summary collapse
- #_load(args) ⇒ Object
- #find(*args) ⇒ Object
- #find_by_id(id) ⇒ Object
- #object_cache_on(*attrs) ⇒ Object
Instance Method Details
#_load(args) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/cache/object/active_record.rb', line 56 def _load(args) attributes = Marshal.load(args) object = allocate object.load_from_cache(attributes) object end |
#find(*args) ⇒ Object
64 65 66 67 68 |
# File 'lib/cache/object/active_record.rb', line 64 def find(*args) Cache::Object.adapter.fetch(self, *args[0]) do super(*args) end end |
#find_by_id(id) ⇒ Object
70 71 72 73 74 |
# File 'lib/cache/object/active_record.rb', line 70 def find_by_id(id) Cache::Object.adapter.fetch(self, id) do where(self.primary_key => id).first end end |
#object_cache_on(*attrs) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/cache/object/active_record.rb', line 76 def object_cache_on(*attrs) self._object_cache_attr_mappings << attrs define_singleton_method("find_by_#{attrs.join('_and_')}") do |*args| attributes = Hash[attrs.zip(args)] Cache::Object.adapter.fetch_mapping(self, attributes) do super(*args) end end end |