Skip to content

Commit f773b0d

Browse files
AlexDWuCh4s3
authored andcommitted
Require bayes_redis_backend (#157)
1 parent 5ac466b commit f773b0d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/classifier-reborn/backends/bayes_redis_backend.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
require_relative 'no_redis_error'
2-
3-
begin
4-
require 'redis'
5-
rescue LoadError
6-
raise NoRedisError
7-
end
2+
# require redis when we run #intialize. This way only people using this backend
3+
# will need to install and load the backend without having to
4+
# require 'classifier-reborn/backends/bayes_redis_backend'
85

96
module ClassifierReborn
107
# This class provides Redis as the storage backend for the classifier data structures
@@ -30,6 +27,12 @@ class BayesRedisBackend
3027
# reconnect_attempts: 1
3128
# inherit_socket: false
3229
def initialize(options = {})
30+
begin # because some people don't have redis installed
31+
require 'redis'
32+
rescue LoadError
33+
raise NoRedisError
34+
end
35+
3336
@redis = Redis.new(options)
3437
@redis.set(:total_words, 0)
3538
@redis.set(:total_trainings, 0)

lib/classifier-reborn/bayes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
require_relative 'category_namer'
88
require_relative 'backends/bayes_memory_backend'
9+
require_relative 'backends/bayes_redis_backend'
910

1011
module ClassifierReborn
1112
class Bayes

0 commit comments

Comments
 (0)