From 12ea886d7d96221345692e9e60efa71907b201a9 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@gmail.com>
Date: Sat, 5 Jan 2013 16:50:09 +0100
Subject: [PATCH] Definition of log file for database in config file

---
 Gemfile        | 1 +
 Gemfile.lock   | 1 +
 Rakefile       | 2 +-
 lib/options.rb | 3 ++-
 run.rb         | 1 +
 5 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Gemfile b/Gemfile
index d75d969..4fba743 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,6 +3,7 @@ gem "rake"
 gem "net-yail"
 gem "rspec"
 gem "activerecord"
+gem "activesupport"
 gem "sqlite3"
 
 gem "youtube_it"
diff --git a/Gemfile.lock b/Gemfile.lock
index f018815..53dfa53 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -59,6 +59,7 @@ PLATFORMS
 
 DEPENDENCIES
   activerecord
+  activesupport
   net-yail
   rake
   rspec
diff --git a/Rakefile b/Rakefile
index 18969ab..4760415 100644
--- a/Rakefile
+++ b/Rakefile
@@ -13,5 +13,5 @@ end
 task :environment do
     config = Options.new.read_file
     ActiveRecord::Base.establish_connection(config[:database])
-    ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a'))
+    ActiveRecord::Base.logger = Logger.new(File.open(config[:database][:log], 'a'))
 end
diff --git a/lib/options.rb b/lib/options.rb
index b942763..69367af 100644
--- a/lib/options.rb
+++ b/lib/options.rb
@@ -1,5 +1,6 @@
 require 'optparse'
 require 'yaml'
+require 'active_support'
 
 # Allow us to get options, set by user or default ones.
 class Options
@@ -43,7 +44,7 @@ class Options
     # Read the options from the configuration file.
     def read_file
         if File.exists?(@file)
-            YAML.load_file(@file).each do |k, v|
+            YAML.load_file(@file).with_indifferent_access.each do |k, v|
                 @options[k.to_sym] = v unless @options.has_key?(k)
             end
         end
diff --git a/run.rb b/run.rb
index c98fbab..b35787b 100755
--- a/run.rb
+++ b/run.rb
@@ -11,6 +11,7 @@ require_relative 'lib/options'
 options = Options.new.read_all
 
 ActiveRecord::Base.establish_connection(options[:database])
+ActiveRecord::Base.logger = Logger.new(File.open(options[:database][:log], 'a'))
 
 bot = PlayBot.new(options)
 bot.irc_loop
-- 
GitLab