Module: Spinel::Config

Included in:
Spinel
Defined in:
lib/spinel/config.rb

Constant Summary collapse

DEFAULT_MIN_COMPLETE =
2
DEFAULT_CACHE_EXPIRE =
600
DEFAULT_MATCH_LIMIT =
10
DEFAULT_DOCUMENT_KEY =
:body
DEFAULT_NAMESPACE =
'spinel'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_expireObject


15
16
17
# File 'lib/spinel/config.rb', line 15

def cache_expire
  @cache_expire ||= DEFAULT_CACHE_EXPIRE
end

#document_keyObject


23
24
25
# File 'lib/spinel/config.rb', line 23

def document_key
  (@document_key ||= DEFAULT_DOCUMENT_KEY).to_s
end

#match_limitObject


19
20
21
# File 'lib/spinel/config.rb', line 19

def match_limit
  @match_limit ||= DEFAULT_MATCH_LIMIT
end

#min_completeObject


11
12
13
# File 'lib/spinel/config.rb', line 11

def min_complete
  @min_complete ||= DEFAULT_MIN_COMPLETE
end

#namespaceObject


27
28
29
# File 'lib/spinel/config.rb', line 27

def namespace
  @namespace ||= DEFAULT_NAMESPACE
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:


55
56
57
58
# File 'lib/spinel/config.rb', line 55

def configure
  yield self
  self
end

#redisObject


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/spinel/config.rb', line 42

def redis
  @redis ||= (
    url = URI(@redis_url || ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0")

    ::Redis.new({
      host:     url.host,
      port:     url.port,
      db:       url.path[1..-1],
      password: url.password
    })
  )
end

#redis=(server) ⇒ Object


31
32
33
34
35
36
37
38
39
40
# File 'lib/spinel/config.rb', line 31

def redis=(server)
  if server.is_a?(String)
    @redis = nil
    @redis_url = server
  else
    @redis = server
  end

  redis
end