Module: Soulheart::Config
- Included in:
- Soulheart
- Defined in:
- lib/soulheart/config.rb
Instance Method Summary collapse
- #base_id ⇒ Object
- #default_normalizer ⇒ Object
- #default_stop_words ⇒ Object
- #jruby? ⇒ Boolean
- #normalizer ⇒ Object
- #normalizer=(str) ⇒ Object
- #normalizer_id ⇒ Object
-
#redis ⇒ Object
Returns the current Redis connection.
-
#redis=(server) ⇒ Object
Accepts: 1.
- #redis_normalizer ⇒ Object
- #redis_stop_words ⇒ Object
- #stop_words ⇒ Object
- #stop_words=(arr) ⇒ Object
- #stop_words_id ⇒ Object
Instance Method Details
#base_id ⇒ Object
40 41 42 |
# File 'lib/soulheart/config.rb', line 40 def base_id ENV['RACK_ENV'] != 'test' ? 'soulheart:' : 'soulheart_test:' end |
#default_normalizer ⇒ Object
71 72 73 |
# File 'lib/soulheart/config.rb', line 71 def default_normalizer '[^\p{Word}\ ]' end |
#default_stop_words ⇒ Object
48 49 50 |
# File 'lib/soulheart/config.rb', line 48 def default_stop_words %w(vs at the) end |
#jruby? ⇒ Boolean
22 23 24 |
# File 'lib/soulheart/config.rb', line 22 def jruby? RUBY_ENGINE == 'jruby' end |
#normalizer ⇒ Object
80 81 82 |
# File 'lib/soulheart/config.rb', line 80 def normalizer @normalizer ||= redis_normalizer || default_normalizer end |
#normalizer=(str) ⇒ Object
84 85 86 87 88 |
# File 'lib/soulheart/config.rb', line 84 def normalizer=(str) redis.expire normalizer_id, 0 @normalizer = str redis.set normalizer_id, @normalizer end |
#normalizer_id ⇒ Object
67 68 69 |
# File 'lib/soulheart/config.rb', line 67 def normalizer_id "#{base_id}normalizer:" end |
#redis ⇒ Object
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 |
#redis_normalizer ⇒ Object
75 76 77 78 |
# File 'lib/soulheart/config.rb', line 75 def redis_normalizer return false unless redis.exists normalizer_id redis.get normalizer_id end |
#redis_stop_words ⇒ Object
52 53 54 55 |
# File 'lib/soulheart/config.rb', line 52 def redis_stop_words return false unless redis.exists stop_words_id redis.lrange(stop_words_id, 0, -1) end |
#stop_words ⇒ Object
57 58 59 |
# File 'lib/soulheart/config.rb', line 57 def stop_words @stop_words ||= redis_stop_words || default_stop_words end |
#stop_words=(arr) ⇒ Object
61 62 63 64 65 |
# File 'lib/soulheart/config.rb', line 61 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 ⇒ Object
44 45 46 |
# File 'lib/soulheart/config.rb', line 44 def stop_words_id "#{base_id}stop_list:" end |