Class: Suitcase::Hotel::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/suitcase/hotel/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Cache

Returns a new instance of Cache.



6
7
8
# File 'lib/suitcase/hotel/cache.rb', line 6

def initialize(store)
  @store = store
end

Instance Attribute Details

#storeObject

Returns the value of attribute store.



4
5
6
# File 'lib/suitcase/hotel/cache.rb', line 4

def store
  @store
end

Instance Method Details

#cached?(action, params) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/suitcase/hotel/cache.rb', line 32

def cached?(action, params)
  string_params = keys_to_strings(params)
  @store[action] && @store[action][string_params]
end

#get_query(action, params) ⇒ Object



23
24
25
26
# File 'lib/suitcase/hotel/cache.rb', line 23

def get_query(action, params)
  string_params = keys_to_strings(params)
  @store[action] ? @store[action][string_params] : nil
end

#keysObject



28
29
30
# File 'lib/suitcase/hotel/cache.rb', line 28

def keys
  @store.keys
end

#save_query(action, params, response) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/suitcase/hotel/cache.rb', line 10

def save_query(action, params, response)
  %w(apiKey cid customerSessionId customerIpAddress locale
  customerUserAgent).each do |param|
    params.delete(param)
  end
  params.delete("currencyCode") unless action == :paymentInfo

  string_params = keys_to_strings(params)

  @store[action] ||= {}
  @store[action] = @store[action].merge(string_params => response)
end

#undefine_query(action, params) ⇒ Object



37
38
39
40
# File 'lib/suitcase/hotel/cache.rb', line 37

def undefine_query(action, params)
  string_params = keys_to_strings(params)
  @store[action].delete(string_params) if @store[action]
end