Class: Outlander::Agent

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/outlander/agent.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_storageObject

Returns the value of attribute cache_storage.



10
11
12
# File 'lib/outlander/agent.rb', line 10

def cache_storage
  @cache_storage
end

Class Method Details

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



13
14
15
16
17
18
19
20
21
# File 'lib/outlander/agent.rb', line 13

def self.fetch(path, options = {}, &block)
  if cache_enabled? && options[:cache]
    response_body = @cache_storage.get(path) || get(path, options, &block).body
    @cache_storage.set(path, response_body)
    response_body
  else
    get(path, options, &block).body
  end
end

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



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/outlander/agent.rb', line 23

def self.method_missing(m, *args, &block)
  if m.to_s.end_with? '_with_cache'
    if cache_enabled?
      response_body = @cache_storage.get(args[0]) || get(*args, &block).body
      @cache_storage.set(args[0], response_body)
      response_body
    else
      get(*args, &block).body
    end
  end
end