Class: ApiResource::Decorators::CachingDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/api_resource/decorators/caching_decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, ttl) ⇒ CachingDecorator

Returns a new instance of CachingDecorator.



7
8
9
10
# File 'lib/api_resource/decorators/caching_decorator.rb', line 7

def initialize(owner, ttl)
  @owner = owner
  @ttl = ttl
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



13
14
15
16
17
# File 'lib/api_resource/decorators/caching_decorator.rb', line 13

def method_missing(method_name, *args, &block)
  ApiResource.with_ttl(self.ttl) do
    self.owner.send(method_name, *args, &block)
  end
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



4
5
6
# File 'lib/api_resource/decorators/caching_decorator.rb', line 4

def owner
  @owner
end

#ttlObject (readonly)

Returns the value of attribute ttl.



5
6
7
# File 'lib/api_resource/decorators/caching_decorator.rb', line 5

def ttl
  @ttl
end