Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extracted to soulmate/config module

  • Loading branch information...
commit 56cc3e96792ca0d2bb8b66e7527ebba9ecfc23cd 1 parent 2a00a26
HungYuHei HungYuHei authored
Showing with 54 additions and 46 deletions.
  1. +2 −46 lib/soulmate.rb
  2. +52 −0 lib/soulmate/config.rb
48 lib/soulmate.rb
View
@@ -1,56 +1,12 @@
-require 'uri'
require 'multi_json'
-require 'redis'
require 'soulmate/version'
require 'soulmate/helpers'
require 'soulmate/base'
require 'soulmate/matcher'
require 'soulmate/loader'
+require 'soulmate/config'
module Soulmate
-
- extend self
-
- DEFAULT_MIN_COMPLETE = 2
- DEFAULT_STOP_WORDS = ["vs", "at", "the"]
-
- attr_writer :min_complete
-
- def min_complete
- @min_complete ||= DEFAULT_MIN_COMPLETE
- end
-
- def redis=(server)
- if server.is_a?(String)
- @redis = nil
- @redis_url = server
- else
- @redis = server
- end
-
- redis
- end
-
- 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
-
- def stop_words
- @stop_words ||= DEFAULT_STOP_WORDS
- end
-
- def stop_words=(arr)
- @stop_words = Array(arr).flatten
- end
-
+ extend Config
end
52 lib/soulmate/config.rb
View
@@ -0,0 +1,52 @@
+require 'uri'
+require 'redis'
+
+module Soulmate
+ module Config
+ DEFAULT_MIN_COMPLETE = 2
+ DEFAULT_STOP_WORDS = ["vs", "at", "the"]
+
+ attr_writer :min_complete
+
+ def min_complete
+ @min_complete ||= DEFAULT_MIN_COMPLETE
+ end
+
+ # Accepts:
+ # 1. A Redis URL String 'redis://host:port/db'
+ # 2. An existing instance of Redis, Redis::Namespace, etc.
+ def redis=(server)
+ if server.is_a?(String)
+ @redis = nil
+ @redis_url = server
+ else
+ @redis = server
+ end
+
+ redis
+ end
+
+ # Returns the current Redis connection. If none has been created, will
+ # create a new one.
+ 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
+
+ def stop_words
+ @stop_words ||= DEFAULT_STOP_WORDS
+ end
+
+ def stop_words=(arr)
+ @stop_words = Array(arr).flatten
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.