Module: CacheableDelegator
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cacheable_delegator.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- EXCLUDED_FIELDS =
[:id, :cache_created_at, :cache_updated_at, :source_record_id, :source_record_type]
- COL_ATTRIBUTES_TO_UPGRADE =
[:limit, :name, :null, :precision, :scale, :sql_type, :type]
- DELEGATING_REGEX =
/^delegate_(\w+)/
Instance Method Summary collapse
- #method_missing(foo, *args, &block) ⇒ Object
-
#refresh_cache(opts = {}) ⇒ Object
instance method pre: must already have source_record set.
- #refresh_cache!(opts = {}) ⇒ Object
- #respond_to?(meth, x = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(foo, *args, &block) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/cacheable_delegator.rb', line 157 def method_missing(foo, *args, &block) if foomatch = foo.to_s.match(DELEGATING_REGEX) foo = foomatch[1].to_s self.source_record.send(foo, *args, &block) elsif source_record.respond_to?(foo) source_record.send(foo, *args, &block) else super end end |
Instance Method Details
#refresh_cache(opts = {}) ⇒ Object
instance method pre: must already have source_record set
211 212 213 214 215 216 217 218 |
# File 'lib/cacheable_delegator.rb', line 211 def refresh_cache(opts={}) atts = self.class.build_attributes_hash(self.source_record) opts[:without_protection] ||= true self.assign_attributes(atts, opts) self end |
#refresh_cache!(opts = {}) ⇒ Object
220 221 222 223 |
# File 'lib/cacheable_delegator.rb', line 220 def refresh_cache!(opts={}) refresh_cache(opts) self.save end |
#respond_to?(meth, x = false) ⇒ Boolean
168 169 170 171 172 173 174 175 176 |
# File 'lib/cacheable_delegator.rb', line 168 def respond_to?(meth, x=false) if meth.match(DELEGATING_REGEX) true elsif source_record.respond_to?(meth) true else super end end |