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
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cacheable_delegator.rb', line 155 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
209 210 211 212 213 214 215 216 |
# File 'lib/cacheable_delegator.rb', line 209 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
218 219 220 221 222 |
# File 'lib/cacheable_delegator.rb', line 218 def refresh_cache!(opts={}) refresh_cache(opts) self.save end |
#respond_to?(meth, x = false) ⇒ Boolean
166 167 168 169 170 171 172 173 174 |
# File 'lib/cacheable_delegator.rb', line 166 def respond_to?(meth, x=false) if meth.match(DELEGATING_REGEX) true elsif source_class.method_defined?(meth) true else super end end |