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.



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

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)


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

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



34
35
36
# File 'lib/halo-api/client.rb', line 34

def cached?
  cache_store[:cached]
end

#set_up_cache(redis_url, ttl) ⇒ Object



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

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