Class: Api::Cache

Inherits:
Object
  • Object
show all
Defined in:
app/caches/api/cache.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Cache


9
10
# File 'app/caches/api/cache.rb', line 9

def initialize(options = {}, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


16
17
18
19
20
21
22
# File 'app/caches/api/cache.rb', line 16

def method_missing(m, *args, &block)
  key = "#{m}-#{args.to_json}-#{block.to_json}"
  # raise key
  output = @cachable.call.send(m, *args, &block)
  # raise output.inspect
  output
end

Class Method Details

.cache(options = {}, &block) ⇒ Object


3
4
5
6
7
# File 'app/caches/api/cache.rb', line 3

def self.cache(options = {}, &block)
  instance = new(options = {})
  instance.prepare_cache(&block)
  instance
end

Instance Method Details

#prepare_cache(&block) ⇒ Object


12
13
14
# File 'app/caches/api/cache.rb', line 12

def prepare_cache(&block)
  @cachable = block
end