worlddb 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7c9137d81e29c751381a6a489626e295cea4619
4
- data.tar.gz: c8fb56e5b4f5bcf7e8364c67c4f795a01d464053
3
+ metadata.gz: f834f636b29a1231453e74665621584e008559d3
4
+ data.tar.gz: ac4fa3099c8d7862b87ee474fe5e942e4679a93a
5
5
  SHA512:
6
- metadata.gz: e338f8332bad32c4e567f4fe7c754e9f90a0ee0fa3d790b9ad59ca856dfcb28d6e2a0bcad0c74ed8ab10245b498b4d4d70dfb17ce971288a717b8573e417b065
7
- data.tar.gz: 86ad1f3b50b857a9540320b339a1ef4ee4bcebd2c2d9aa9ff3b71384e638c748003cfba65cf9f7e042dc23c8c8cacd71b9aecab7d9e70320ab92159bfb23d881
6
+ metadata.gz: d616d30efdda6a37fe07dc07e39e3fabc97b769839fb2eaf294dd4708afda4981fac8968a16b0c33c2dc43daedc796b10572966ab4510e1e20c7aa57cbdba5d4
7
+ data.tar.gz: 9d8bce8fb4ad6eac3a65b7daa0697b11ccb1276464d9758a291d4b00e50ccbe65d0b976d726f66ec4e220eb007a99c76a01164fdb594828d1d972f8a50bac80b
data/Manifest.txt CHANGED
@@ -37,7 +37,6 @@ lib/worlddb/readers/region.rb
37
37
  lib/worlddb/readers/usage.rb
38
38
  lib/worlddb/schema.rb
39
39
  lib/worlddb/stats.rb
40
- lib/worlddb/stats_comp.rb
41
40
  lib/worlddb/version.rb
42
41
  test/helper.rb
43
42
  test/test_fixture_matchers.rb
@@ -64,17 +64,10 @@ def connect_to_db( options )
64
64
 
65
65
  puts "working directory: #{Dir.pwd}"
66
66
 
67
- db_config = {
68
- :adapter => 'sqlite3',
69
- :database => "#{options.db_path}/#{options.db_name}"
70
- }
67
+ WorldDb.connect( adapter: 'sqlite3',
68
+ database: "#{options.db_path}/#{options.db_name}" )
71
69
 
72
- puts "Connecting to db using settings: "
73
- pp db_config
74
-
75
- ActiveRecord::Base.establish_connection( db_config )
76
-
77
- LogDb.setup # turn on logging to db
70
+ LogDb.setup # turn on logging to db (that is, log to logs table in db)
78
71
  end
79
72
 
80
73
 
@@ -84,10 +77,7 @@ command [:create] do |c|
84
77
 
85
78
  connect_to_db( opts )
86
79
 
87
- LogDb.create
88
- ConfDb.create
89
- TagDb.create
90
- WorldDb.create
80
+ WorldDb.create_all
91
81
 
92
82
  puts 'Done.'
93
83
  end # action
@@ -110,10 +100,7 @@ command [:setup,:s] do |c|
110
100
  ## todo: document optional setup profile arg (defaults to all)
111
101
  setup = args[0] || 'all'
112
102
 
113
- LogDb.create
114
- ConfDb.create
115
- TagDb.create
116
- WorldDb.create
103
+ WorldDb.create_all
117
104
 
118
105
  WorldDb.read_setup( "setups/#{setup}", opts.data_path )
119
106
 
@@ -202,7 +189,7 @@ command :props do |c|
202
189
  connect_to_db( opts )
203
190
 
204
191
  ### fix: use ConfDb.dump or similar (for reuse) !!!
205
- WorldDb.props
192
+ ## WorldDb.props
206
193
 
207
194
  puts 'Done.'
208
195
  end
data/lib/worlddb/stats.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module WorldDb
4
4
 
5
5
  class Stats
6
- include WorldDb::Models
6
+ include Models
7
7
 
8
8
  def tables
9
9
  puts "Stats:"
@@ -4,7 +4,7 @@ module WorldDb
4
4
  # sync version w/ sport.db n friends - why? why not?
5
5
  MAJOR = 2 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 0
7
- PATCH = 8
7
+ PATCH = 9
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
data/lib/worlddb.rb CHANGED
@@ -17,7 +17,7 @@ require 'yaml'
17
17
 
18
18
  # 3rd party gems / libs
19
19
 
20
- require 'zip'
20
+ require 'zip' ## rubyzip gem
21
21
 
22
22
  require 'active_record' ## todo: add sqlite3? etc.
23
23
 
@@ -69,7 +69,6 @@ require 'worlddb/reader_file'
69
69
  require 'worlddb/reader_zip'
70
70
  require 'worlddb/deleter'
71
71
  require 'worlddb/stats'
72
- require 'worlddb/stats_comp'
73
72
 
74
73
 
75
74
  module WorldDb
@@ -84,6 +83,13 @@ module WorldDb
84
83
  ConfDb::Model::Prop.create!( key: 'db.schema.world.version', value: VERSION )
85
84
  end
86
85
 
86
+ def self.create_all
87
+ LogDb.create # add logs table
88
+ ConfDb.create # add props table
89
+ TagDb.create # add tags, taggings table
90
+ WorldDb.create
91
+ end
92
+
87
93
 
88
94
  def self.read( ary, include_path )
89
95
  reader = Reader.new( include_path )
@@ -115,23 +121,82 @@ module WorldDb
115
121
  Deleter.new.run
116
122
  end # method delete!
117
123
 
124
+ def self.delete_all!( opts={} )
125
+ LogDb.delete!
126
+ ConfDb.delete!
127
+ TagDb.delete!
128
+ WorldDb.delete!
129
+ end
130
+
131
+
118
132
  ####
119
133
  ## todo: remove stats ??? why? why not? better use .tables
120
134
  def self.stats
121
- stats = Stats.new
122
- stats.tables
123
- ### stats.props
135
+ Stats.new.tables
124
136
  end
125
137
 
126
138
  def self.tables
127
139
  Stats.new.tables
128
140
  end
129
141
 
130
- def self.props
131
- ### fix: use ConfDb.props delegate or similar !!!
132
- Stats.new.props
142
+
143
+ def self.connect( db_config={} )
144
+
145
+ if db_config.empty?
146
+ puts "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
147
+
148
+ ### change default to ./sport.db ?? why? why not?
149
+ db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///world.db' )
150
+
151
+ if db.scheme == 'postgres'
152
+ config = {
153
+ adapter: 'postgresql',
154
+ host: db.host,
155
+ port: db.port,
156
+ username: db.user,
157
+ password: db.password,
158
+ database: db.path[1..-1],
159
+ encoding: 'utf8'
160
+ }
161
+ else # assume sqlite3
162
+ config = {
163
+ adapter: db.scheme, # sqlite3
164
+ database: db.path[1..-1] # world.db (NB: cut off leading /, thus 1..-1)
165
+ }
166
+ end
167
+ else
168
+ config = db_config # use passed in config hash
169
+ end
170
+
171
+ ## todo/check: use if defined?( JRUBY_VERSION ) instead ??
172
+ if RUBY_PLATFORM =~ /java/ && config[:adapter] == 'sqlite3'
173
+ # quick hack for JRuby sqlite3 support via jdbc
174
+ puts "jruby quick hack - adding jdbc libs for jruby sqlite3 database support"
175
+ require 'jdbc/sqlite3'
176
+ require 'active_record/connection_adapters/jdbc_adapter'
177
+ require 'active_record/connection_adapters/jdbcsqlite3_adapter'
178
+ end
179
+
180
+ puts "Connecting to db using settings: "
181
+ pp config
182
+ ActiveRecord::Base.establish_connection( config )
183
+ # ActiveRecord::Base.logger = Logger.new( STDOUT )
133
184
  end
134
185
 
186
+
187
+ def self.setup_in_memory_db
188
+
189
+ # Database Setup & Config
190
+ ActiveRecord::Base.logger = Logger.new( STDOUT )
191
+ ## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
192
+
193
+ self.connect( adapter: 'sqlite3',
194
+ database: ':memory:' )
195
+
196
+ ## build schema
197
+ WorldDb.create_all
198
+ end # setup_in_memory_db (using SQLite :memory:)
199
+
135
200
  end # module WorldDb
136
201
 
137
202
 
data/test/helper.rb CHANGED
@@ -24,31 +24,6 @@ Lang = WorldDb::Model::Lang
24
24
  Usage = WorldDb::Model::Usage
25
25
 
26
26
 
27
- def setup_in_memory_db
28
- # Database Setup & Config
29
27
 
30
- db_config = {
31
- adapter: 'sqlite3',
32
- database: ':memory:'
33
- }
28
+ WorldDb.setup_in_memory_db
34
29
 
35
- pp db_config
36
-
37
- ActiveRecord::Base.logger = Logger.new( STDOUT )
38
- ## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
39
-
40
- ## NB: every connect will create a new empty in memory db
41
- ActiveRecord::Base.establish_connection( db_config )
42
-
43
-
44
- ## build schema
45
-
46
- LogDb.create
47
- ConfDb.create
48
-
49
- TagDb.create
50
- WorldDb.create
51
- end
52
-
53
-
54
- setup_in_memory_db()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props
@@ -186,7 +186,6 @@ files:
186
186
  - lib/worlddb/readers/usage.rb
187
187
  - lib/worlddb/schema.rb
188
188
  - lib/worlddb/stats.rb
189
- - lib/worlddb/stats_comp.rb
190
189
  - lib/worlddb/version.rb
191
190
  - test/helper.rb
192
191
  - test/test_fixture_matchers.rb
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb
4
-
5
- class Stats
6
-
7
- #
8
- # fix: move to ConfDb for (re)use - do not use - use Props.dump or similar!!!!!
9
-
10
- def props
11
- puts "deprecated API - WorldDb::Stats.props -- use Props.dump or similar"
12
-
13
- puts "Props:"
14
- Prop.order( 'created_at asc' ).all.each do |prop|
15
- puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
16
- end
17
- end
18
- end # class Stats
19
-
20
-
21
- end # module WorldDb