Module: Soulheart::Config

Included in:
Soulheart
Defined in:
lib/soulheart/config.rb

Constant Summary collapse

DEFAULT_STOP_WORDS =
%w(vs at the)

Instance Method Summary collapse

Instance Method Details

#jruby?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/soulheart/config.rb', line 22

def jruby?
  RUBY_ENGINE == 'jruby'
end

#redisObject

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



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/soulheart/config.rb', line 28

def redis
  @redis ||= (
    url = URI(@redis_url || ENV['REDIS_URL'] || 'redis://127.0.0.1:6379/0')
    ::Redis.new(          # 
      driver: (jruby? ? :ruby : :hiredis),
      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.


11
12
13
14
15
16
17
18
19
20
# File 'lib/soulheart/config.rb', line 11

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

  redis
end

#stop_wordsObject



40
41
42
# File 'lib/soulheart/config.rb', line 40

def stop_words
  @stop_words ||= DEFAULT_STOP_WORDS
end

#stop_words=(arr) ⇒ Object



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

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