Class: Halo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/halo-api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
# File 'lib/halo-api/client.rb', line 7

def initialize(options = {})
  options = Halo.options.merge(options)

  Halo::Configuration::OPTIONS.each do |key|
    send("#{key}=", options[key])
  end

  set_up_cache(options.delete(:redis), options.delete(:ttl))
end

Instance Method Details

#cache_storeHash

Returns an options hash with cache keys

Returns:

  • (Hash)


27
28
29
30
31
32
33
# File 'lib/halo-api/client.rb', line 27

def cache_store
  {
    redis: @redis,
    ttl: @ttl,
    cached: @cached
  }
end

#cached?Boolean

Returns true if the request should be cached.

Returns:

  • (Boolean)

    true if the request should be cached



36
37
38
# File 'lib/halo-api/client.rb', line 36

def cached?
  cache_store[:cached]
end

#set_up_cache(redis_url, ttl) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/halo-api/client.rb', line 17

def set_up_cache(redis_url, ttl)
  return @cached = false unless redis_url

  @ttl = ttl || Halo::Configuration::DEFAULT_TTL
  @cached = true
  @redis = Redis.new url: redis_url
end