nachof-zheng 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/config/default.yaml +1 -0
  2. data/config/init.rb +38 -0
  3. metadata +3 -1
@@ -0,0 +1 @@
1
+ :database: sqlite://<%= File.expand_path '~/.zheng.db' %>
data/config/init.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'sequel'
3
+ require 'erb'
4
+
5
+ require 'shellwords' # Needed for parsing the script action
6
+
7
+ require 'logger'
8
+
9
+ require 'ftools'
10
+
11
+ Dir.chdir File.join(File.dirname(__FILE__), '..')
12
+
13
+ def config
14
+ $__config ||= (
15
+ user_conf = File.expand_path('~/.zheng.yaml')
16
+ default_conf = File.join(File.dirname(__FILE__), 'default.yaml')
17
+ File.copy(default_conf, user_conf) unless File.exist? user_conf
18
+ YAML.load(ERB.new(File.read(user_conf)).result)
19
+ )
20
+ end
21
+
22
+ if ENV['ENVIRONMENT'] == 'test'
23
+ logger = Logger.new(File.join(File.dirname(__FILE__), '..', 'logs', 'test.log'))
24
+ DB = Sequel.sqlite "", :loggers => [ logger ]
25
+ else
26
+ DB = Sequel.connect(config[:database])
27
+ end
28
+
29
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'zheng'))
30
+
31
+ # This will create the tables only if they don't already exist.
32
+ # This should be done using Sequel's table_exists? method, but it always returns true.
33
+ begin
34
+ DB.from(:players).first
35
+ rescue
36
+ Zheng::Player.create_table
37
+ Zheng::Game.create_table
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nachof-zheng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nacho Facello
@@ -39,7 +39,9 @@ files:
39
39
  - lib/zheng/player.rb
40
40
  - lib/zheng/rating.rb
41
41
  - lib/zheng/util.rb
42
+ - config/init.rb
42
43
  - lib/zheng.rb
44
+ - config/default.yaml
43
45
  - README.rdoc
44
46
  - LICENSE
45
47
  has_rdoc: false