module Soulheart::Config

Public Instance Methods

base_id() click to toggle source
# File lib/soulheart/config.rb, line 41
def base_id
  ENV['RACK_ENV'] != 'test' ? 'soulheart:' : 'soulheart_test:'
end
default_normalizer() click to toggle source
# File lib/soulheart/config.rb, line 72
def default_normalizer
  '[^\p{Word}\ ]'
end
default_stop_words() click to toggle source
# File lib/soulheart/config.rb, line 49
def default_stop_words
  %w(vs at the)
end
jruby?() click to toggle source
# File lib/soulheart/config.rb, line 23
def jruby?
  RUBY_ENGINE == 'jruby'
end
normalizer() click to toggle source
# File lib/soulheart/config.rb, line 81
def normalizer
  @normalizer ||= redis_normalizer || default_normalizer
end
normalizer=(str) click to toggle source
# File lib/soulheart/config.rb, line 85
def normalizer=(str)
  redis.expire normalizer_id, 0
  @normalizer = str
  redis.set normalizer_id, @normalizer
end
normalizer_id() click to toggle source
# File lib/soulheart/config.rb, line 68
def normalizer_id
  "#{base_id}normalizer:"
end
redis() click to toggle source

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

# File lib/soulheart/config.rb, line 29
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) click to toggle source

Accepts:

1. A Redis URL String 'redis://host:port/db'
2. An existing instance of Redis, Redis::Namespace, etc.
# File lib/soulheart/config.rb, line 12
def redis=(server)
  if server.is_a?(String)
    @redis = nil
    @redis_url = server
  else
    @redis = server
  end

  redis
end
redis_normalizer() click to toggle source
# File lib/soulheart/config.rb, line 76
def redis_normalizer
  return false unless redis.exists normalizer_id
  redis.get normalizer_id
end
redis_stop_words() click to toggle source
# File lib/soulheart/config.rb, line 53
def redis_stop_words
  return false unless redis.exists stop_words_id
  redis.lrange(stop_words_id, 0, -1) 
end
stop_words() click to toggle source
# File lib/soulheart/config.rb, line 58
def stop_words
  @stop_words ||= redis_stop_words || default_stop_words
end
stop_words=(arr) click to toggle source
# File lib/soulheart/config.rb, line 62
def stop_words=(arr)
  redis.expire stop_words_id, 0
  @stop_words = Array(arr).flatten
  redis.lpush stop_words_id, @stop_words
end
stop_words_id() click to toggle source
# File lib/soulheart/config.rb, line 45
def stop_words_id
  "#{base_id}stop_list:"
end