Module: CachedRecord::ORM::InstanceMethods
- Defined in:
- lib/cached_record/orm.rb
Instance Method Summary collapse
- #as_cache_json ⇒ Object
- #cache ⇒ Object
- #cache_attributes ⇒ Object
- #cache_foreign_keys ⇒ Object
- #expire ⇒ Object
- #merge_cache_json(attributes, variables) ⇒ Object
- #to_cache_json ⇒ Object
Instance Method Details
#as_cache_json ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/cached_record/orm.rb', line 147 def as_cache_json attributes = {:id => id}.merge cache_attributes variables = ([:memoize] || {}).inject({}) do |hash, (method, variable)| hash[variable] = send method hash end merge_cache_json attributes, variables end |
#cache ⇒ Object
169 170 171 172 |
# File 'lib/cached_record/orm.rb', line 169 def cache self.class.cached id true end |
#cache_attributes ⇒ Object
139 140 141 |
# File 'lib/cached_record/orm.rb', line 139 def cache_attributes raise NotImplementedError, "Cannot return cache attributes for `#{self.class}` instances" end |
#cache_foreign_keys ⇒ Object
143 144 145 |
# File 'lib/cached_record/orm.rb', line 143 def cache_foreign_keys raise NotImplementedError, "Cannot return cache foreign keys for `#{self.class}` instances" end |
#expire ⇒ Object
174 175 176 177 |
# File 'lib/cached_record/orm.rb', line 174 def expire Cache.expire self true end |
#merge_cache_json(attributes, variables) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/cached_record/orm.rb', line 156 def merge_cache_json(attributes, variables) if [:include_root] variables = variables.inject({}){|h, (k, v)| h[k.to_s.gsub(/^@/, "").to_sym] = v; h} {self.class.cache_root => attributes}.merge variables else attributes.merge variables end end |
#to_cache_json ⇒ Object
165 166 167 |
# File 'lib/cached_record/orm.rb', line 165 def to_cache_json as_cache_json.to_json end |