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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(foo, *args, &block) ⇒ Object



137
138
139
140
141
142
143
144
145
146
# File 'lib/cacheable_delegator.rb', line 137

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

#respond_to?(meth, x = false) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
154
155
156
# File 'lib/cacheable_delegator.rb', line 148

def respond_to?(meth, x=false)
  if meth.match(DELEGATING_REGEX)
    true
  elsif source_record.respond_to?(meth)
    true
  else
    super
  end
end