Module: Spinel::Config

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

Constant Summary collapse

DEFAULT_MINIMAL_WORD =
2
DEFAULT_CACHE_EXPIRE =
600
DEFAULT_SEARCH_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

#minimal_wordObject



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

def minimal_word
  @minimal_word ||= DEFAULT_MINIMAL_WORD
end

#namespaceObject



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

def namespace
  @namespace ||= DEFAULT_NAMESPACE
end

#search_limitObject



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

def search_limit
  @search_limit ||= DEFAULT_SEARCH_LIMIT
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



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

def configure
  yield self
  self
end

#redisObject



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

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
# 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