lib/chatterbot/config.rb in chatterbot-0.2.8 vs lib/chatterbot/config.rb in chatterbot-0.2.9
- old
+ new
@@ -33,10 +33,17 @@
# do we have a DB connection string?
def has_db?
has_sequel? && config.has_key?(:db_uri)
end
+ def debug_mode=(d)
+ config[:debug_mode] = d
+ end
+ def no_update=(d)
+ config[:no_update] = d
+ end
+
#
# are we in debug mode?
def debug_mode?
config[:debug_mode] || false
end
@@ -51,10 +58,14 @@
# should we write to a log file?
def logging?
has_config? && config.has_key?(:log_dest)
end
+ def verbose=(v)
+ config[:verbose] = v
+ end
+
def verbose?
config[:verbose] || false
end
#
@@ -131,13 +142,35 @@
def needs_auth_token?
config[:token].nil?
end
#
+ # determine if we're being called by one of our internal scripts
+ #
+ def chatterbot_helper?
+ File.basename($0).include?("chatterbot-")
+ end
+
+ #
+ # if we are called by a bot, we want to use the directory of that
+ # script. If we are called by chatterbot-register or another
+ # helper script, we want to use the current working directory
+ #
+ def working_dir
+ if chatterbot_helper?
+ Dir.getwd
+ else
+ File.dirname($0)
+ end
+ end
+
+ #
# figure out what config file to load based on the name of the bot
def config_file
- File.join(File.expand_path(File.dirname($0)), "#{botname}.yml")
+ dest = working_dir
+
+ x = File.join(File.expand_path(dest), "#{botname}.yml")
end
#
# load in a config file
def slurp_file(f)
@@ -162,17 +195,18 @@
# a file specified in ENV
ENV["chatterbot_config"],
# 'global' config file local to the path of the ruby script
- File.join(File.dirname(File.expand_path($0)), "global.yml")
+ File.join(working_dir, "global.yml")
].compact
end
#
# get any config from our global config files
def global_config
tmp = {}
+
global_config_files.each { |f|
tmp.merge!(slurp_file(f) || {})
}
tmp
end