Module: CacheableDelegator

Extended by:
ActiveSupport::Concern
Defined in:
lib/cacheable_delegator.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

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



24
25
26
27
28
29
30
31
32
# File 'lib/cacheable_delegator.rb', line 24

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)
  else
    super
  end
end

Instance Method Details

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

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/cacheable_delegator.rb', line 34

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