Module: Soulmate::Config

Included in:
Soulmate
Defined in:
lib/soulmate/config.rb

Constant Summary collapse

DEFAULT_MIN_COMPLETE =
2
DEFAULT_STOP_WORDS =
["vs", "at", "the"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#min_completeObject



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

def min_complete
  @min_complete ||= DEFAULT_MIN_COMPLETE
end

Instance Method Details

#redisObject

Returns the current Redis connection. If none has been created, will create a new one.



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

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

Accepts:

1. A Redis URL String 'redis://host:port/db'
2. An existing instance of Redis, Redis::Namespace, etc.


18
19
20
21
22
23
24
25
26
27
# File 'lib/soulmate/config.rb', line 18

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

  redis
end

#stop_wordsObject



44
45
46
# File 'lib/soulmate/config.rb', line 44

def stop_words
  @stop_words ||= DEFAULT_STOP_WORDS
end

#stop_words=(arr) ⇒ Object



48
49
50
# File 'lib/soulmate/config.rb', line 48

def stop_words=(arr)
  @stop_words = Array(arr).flatten
end