sportdb 1.9.15 → 1.9.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c5d5f460f4f9a47f7972f979e24a3c5652e07a8
4
- data.tar.gz: a703aeb762e8fedefdf6e91e4f92bad6c59c1bd4
3
+ metadata.gz: f652191b23c1c3acab00a7b950f7b93ec6bce4f4
4
+ data.tar.gz: 85fe028e22fa00c0ee763ba6f472c0d23016009e
5
5
  SHA512:
6
- metadata.gz: 059df898468b056c66c0a1a08cbcac20ce4b55519069d5cd90251e7c00db9d96de01fba73d6a3a2695c0f5f62e1d90c23f08a28ebe92d7d5b49d2a672d4fd4f8
7
- data.tar.gz: 84e24316d647343aa7cebc1872bb07728984df9b9d2942ecc6431ab20e1bfca1b2848cd9c7c3b3c49b70992ce26f8594adc250d091ef69dc45600b7d08e4764d
6
+ metadata.gz: e175cc5dbd766ef735bb4c00a7d2afd47466c1aa3543fe2911a26b696b80b2b18a832ad85e2dc9f9575804a441b6c2471daa2779c1bfec8cbdd2452bbd202877
7
+ data.tar.gz: 21136016a7ea1294f86f1064bc9f604613936d6f8e016fd53144337f1894fa5b7ee8e4453bb3aa83cb5a82e556764509e7d0befd4793fe6583b7c200ad5b5c27
@@ -65,12 +65,6 @@ require 'sportdb/models/stats/group_standing_entry'
65
65
 
66
66
  require 'sportdb/models/utils' # e.g. GameCursor
67
67
 
68
- ## add backwards compatible n convenience namespace
69
- ### move to forward.rb ?? - why? why not??
70
- module SportDb
71
- Models = Model
72
- end
73
-
74
68
 
75
69
  require 'sportdb/schema' # NB: requires sportdb/models (include SportDB::Models)
76
70
 
@@ -150,6 +144,17 @@ module SportDb
150
144
  ConfDb::Model::Prop.create!( key: 'db.schema.sport.version', value: VERSION )
151
145
  end
152
146
 
147
+ def self.create_all
148
+ ## build schema - convenience helper
149
+ LogDb.create
150
+ ConfDb.create
151
+ TagDb.create
152
+ WorldDb.create
153
+ PersonDb.create
154
+ SportDb.create
155
+ end
156
+
157
+
153
158
  def self.read_setup( setup, include_path )
154
159
  reader = Reader.new( include_path )
155
160
  reader.load_setup( setup )
@@ -197,40 +202,69 @@ module SportDb
197
202
 
198
203
 
199
204
  def self.stats
200
- stats = Stats.new
201
- stats.tables
202
- stats.props
205
+ Stats.new.tables # NOTE: same as tables (remove??? why? why not??)
203
206
  end
204
207
 
205
208
  def self.tables
206
209
  Stats.new.tables
207
210
  end
208
211
 
209
- ### fix:
210
- ## remove - use ConfDb.dump or similar -- add api depreciated
211
- def self.props
212
- Stats.new.props
212
+
213
+ def self.connect( db_config={} )
214
+
215
+ if db_config.empty?
216
+ puts "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
217
+
218
+ ### change default to ./sport.db ?? why? why not?
219
+ db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///sport.db' )
220
+
221
+ if db.scheme == 'postgres'
222
+ config = {
223
+ adapter: 'postgresql',
224
+ host: db.host,
225
+ port: db.port,
226
+ username: db.user,
227
+ password: db.password,
228
+ database: db.path[1..-1],
229
+ encoding: 'utf8'
230
+ }
231
+ else # assume sqlite3
232
+ config = {
233
+ adapter: db.scheme, # sqlite3
234
+ database: db.path[1..-1] # sport.db (NB: cut off leading /, thus 1..-1)
235
+ }
236
+ end
237
+ else
238
+ config = db_config # use passed in config hash
239
+ end
240
+
241
+ ## todo/check: use if defined?( JRUBY_VERSION ) instead ??
242
+ if RUBY_PLATFORM =~ /java/ && config[:adapter] == 'sqlite3'
243
+ # quick hack for JRuby sqlite3 support via jdbc
244
+ puts "jruby quick hack - adding jdbc libs for jruby sqlite3 database support"
245
+ require 'jdbc/sqlite3'
246
+ require 'active_record/connection_adapters/jdbc_adapter'
247
+ require 'active_record/connection_adapters/jdbcsqlite3_adapter'
248
+ end
249
+
250
+ puts "Connecting to db using settings: "
251
+ pp config
252
+ ActiveRecord::Base.establish_connection( config )
253
+ # ActiveRecord::Base.logger = Logger.new( STDOUT )
213
254
  end
214
255
 
215
256
 
216
257
  def self.setup_in_memory_db
217
- # Database Setup & Config
218
258
 
259
+ # Database Setup & Config
219
260
  ActiveRecord::Base.logger = Logger.new( STDOUT )
220
261
  ## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
221
262
 
222
- ## NB: every connect will create a new empty in memory db
223
- ActiveRecord::Base.establish_connection(
224
- adapter: 'sqlite3',
225
- database: ':memory:' )
263
+ self.connect( adapter: 'sqlite3',
264
+ database: ':memory:' )
226
265
 
227
266
  ## build schema
228
- LogDb.create
229
- ConfDb.create
230
- TagDb.create
231
- WorldDb.create
232
- PersonDb.create
233
- SportDb.create
267
+ SportDb.create_all
234
268
 
235
269
  ## read builtins - why? why not?
236
270
  SportDb.read_builtin
@@ -257,4 +291,4 @@ if __FILE__ == $0
257
291
  else
258
292
  ## say hello
259
293
  puts SportDb.banner
260
- end
294
+ end
@@ -76,27 +76,10 @@ def connect_to_db( options )
76
76
 
77
77
  puts "working directory: #{Dir.pwd}"
78
78
 
79
- db_config = {
80
- :adapter => 'sqlite3',
81
- :database => "#{options.db_path}/#{options.db_name}"
82
- }
83
-
84
- ## todo/check: use if defined?( JRUBY_VERSION ) instead ??
85
- if RUBY_PLATFORM =~ /java/ && db_config[:adapter] == 'sqlite3'
86
- # quick hack for JRuby sqlite3 support via jdbc
87
- puts "jruby quick hack - adding jdbc libs for jruby sqlite3 database support"
88
- require 'jdbc/sqlite3'
89
- require 'active_record/connection_adapters/jdbc_adapter'
90
- require 'active_record/connection_adapters/jdbcsqlite3_adapter'
91
- end
92
-
93
-
94
- puts "Connecting to db using settings: "
95
- pp db_config
79
+ SportDb.connect( adapter: 'sqlite3',
80
+ database: "#{options.db_path}/#{options.db_name}" )
96
81
 
97
- ActiveRecord::Base.establish_connection( db_config )
98
-
99
- LogDb.setup # start logging to db
82
+ LogDb.setup # start logging to db (that is, save logs in logs table in db)
100
83
  end
101
84
 
102
85
 
@@ -105,14 +88,9 @@ command [:create] do |c|
105
88
  c.action do |g,o,args|
106
89
 
107
90
  connect_to_db( opts )
108
-
109
- LogDb.create
110
- ConfDb.create
111
- TagDb.create
112
- WorldDb.create
113
- PersonDb.create
114
- SportDb.create
115
-
91
+
92
+ SportDb.create_all
93
+
116
94
  SportDb.read_builtin # e.g. seasons.txt etc
117
95
 
118
96
  puts 'Done.'
@@ -130,12 +108,7 @@ command [:build,:b] do |c|
130
108
 
131
109
  connect_to_db( opts )
132
110
 
133
- LogDb.create
134
- ConfDb.create
135
- TagDb.create
136
- WorldDb.create
137
- PersonDb.create
138
- SportDb.create
111
+ SportDb.create_all
139
112
 
140
113
  SportDb.read_builtin # e.g. seasons.txt etc
141
114
 
@@ -194,12 +167,7 @@ command [:new,:n] do |c|
194
167
 
195
168
  connect_to_db( opts ) ### todo: check let connect go first?? - for logging (logs) to db ???
196
169
 
197
- LogDb.create
198
- ConfDb.create
199
- TagDb.create
200
- WorldDb.create
201
- PersonDb.create
202
- SportDb.create
170
+ SportDb.create_all
203
171
 
204
172
  SportDb.read_builtin # e.g. seasons.txt etc
205
173
 
@@ -231,12 +199,7 @@ command [:setup,:s] do |c|
231
199
  ## todo: document optional setup profile arg (defaults to all)
232
200
  setup = args[0] || 'all'
233
201
 
234
- LogDb.create
235
- ConfDb.create
236
- TagDb.create
237
- WorldDb.create
238
- PersonDb.create
239
- SportDb.create
202
+ SportDb.create_all
240
203
 
241
204
  SportDb.read_builtin # e.g. seasons.txt etc
242
205
 
@@ -396,8 +359,9 @@ command :props do |c|
396
359
 
397
360
  connect_to_db( opts )
398
361
 
399
- SportDb.props
400
-
362
+ ### fix: SportDb.props
363
+ ## use ConfDb.props or similar!!!
364
+
401
365
  puts 'Done.'
402
366
  end
403
367
  end
@@ -25,7 +25,10 @@ module SportDb
25
25
  class Goal < ActiveRecord::Base ; end
26
26
 
27
27
  end
28
- end
28
+
29
+ ## add backwards compatible n convenience namespace
30
+ Models = Model
31
+ end # module SportDb
29
32
 
30
33
 
31
34
  module WorldDb
@@ -2,7 +2,7 @@
2
2
  module SportDb
3
3
 
4
4
  class Stats
5
- include SportDb::Models
5
+ include Models
6
6
 
7
7
  def tables
8
8
  puts " #{League.count} leagues / #{Season.count} seasons"
@@ -22,15 +22,6 @@ module SportDb
22
22
  ## puts " #{Record.count} records (race|run+person recs)"
23
23
  end
24
24
 
25
- ## fix/chek:
26
- # move to Prop gem / reuse code from Prop gem
27
- def props
28
- puts "Props:"
29
- Prop.order( 'created_at asc' ).all.each do |prop|
30
- puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
31
- end
32
- end
33
-
34
25
  end # class Stats
35
26
 
36
- end # module SportDb
27
+ end # module SportDb
@@ -3,7 +3,7 @@ module SportDb
3
3
 
4
4
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
5
5
  MINOR = 9
6
- PATCH = 15
6
+ PATCH = 16
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.15
4
+ version: 1.9.16
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-29 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