worlddb 1.1.0 → 1.2.0
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.
- data/Rakefile +1 -1
- data/lib/worlddb/cli/main.rb +3 -0
- data/lib/worlddb/reader.rb +20 -22
- data/lib/worlddb/version.rb +1 -1
- metadata +7 -7
data/Rakefile
CHANGED
@@ -19,7 +19,7 @@ Hoe.spec 'worlddb' do
|
|
19
19
|
self.email = 'opensport@googlegroups.com'
|
20
20
|
|
21
21
|
self.extra_deps = [
|
22
|
-
['textutils', '~> 0.
|
22
|
+
['textutils', '~> 0.4.0'],
|
23
23
|
['commander', '~> 4.1.3'],
|
24
24
|
['activerecord', '~> 3.2'] # NB: will include activesupport,etc.
|
25
25
|
### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
|
data/lib/worlddb/cli/main.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'commander/import'
|
4
4
|
|
5
|
+
require 'logutils/db' # add support for logging to db
|
5
6
|
require 'worlddb/cli/opts'
|
6
7
|
|
7
8
|
|
@@ -58,6 +59,8 @@ def connect_to_db( options )
|
|
58
59
|
pp db_config
|
59
60
|
|
60
61
|
ActiveRecord::Base.establish_connection( db_config )
|
62
|
+
|
63
|
+
LogDb.setup # turn on logging to db
|
61
64
|
end
|
62
65
|
|
63
66
|
|
data/lib/worlddb/reader.rb
CHANGED
@@ -2,6 +2,10 @@ module WorldDB
|
|
2
2
|
|
3
3
|
class Reader
|
4
4
|
|
5
|
+
def logger
|
6
|
+
@logger ||= LogUtils[ self ]
|
7
|
+
end
|
8
|
+
|
5
9
|
## make models available in sportdb module by default with namespace
|
6
10
|
# e.g. lets you use City instead of Models::City
|
7
11
|
include WorldDB::Models
|
@@ -10,14 +14,9 @@ class Reader
|
|
10
14
|
## required first arg in ctor!!!
|
11
15
|
## cleanup load_ and remove include_path
|
12
16
|
|
13
|
-
def initialize
|
14
|
-
@logger = LogUtils::Logger.new
|
15
|
-
|
16
|
-
# todo/fix/cleanup: allow initialize( opts = {} ) for logger: logger
|
17
|
+
def initialize
|
17
18
|
end
|
18
19
|
|
19
|
-
attr_reader :logger
|
20
|
-
|
21
20
|
|
22
21
|
def load( name, include_path )
|
23
22
|
|
@@ -92,7 +91,7 @@ class Reader
|
|
92
91
|
|
93
92
|
with_path_for( name, include_path) do |path|
|
94
93
|
|
95
|
-
reader = HashReader.new(
|
94
|
+
reader = HashReader.new( path )
|
96
95
|
|
97
96
|
reader.each do |key, value|
|
98
97
|
|
@@ -128,8 +127,7 @@ class Reader
|
|
128
127
|
|
129
128
|
with_path_for( name, include_path) do |path|
|
130
129
|
|
131
|
-
|
132
|
-
reader = HashReader.new( logger, path )
|
130
|
+
reader = HashReader.new( path )
|
133
131
|
|
134
132
|
grade = 1
|
135
133
|
|
@@ -186,10 +184,10 @@ class Reader
|
|
186
184
|
|
187
185
|
puts "*** parsing data '#{name}' (#{path})..."
|
188
186
|
|
189
|
-
reader = HashReader.new(
|
187
|
+
reader = HashReader.new( path )
|
190
188
|
|
191
189
|
reader.each do |key, value|
|
192
|
-
|
190
|
+
logger.debug " adding langs >>#{value}<<to country >>#{key}<<"
|
193
191
|
|
194
192
|
country = Country.find_by_key!( key )
|
195
193
|
|
@@ -215,7 +213,7 @@ class Reader
|
|
215
213
|
|
216
214
|
puts "*** parsing data '#{name}' (#{path})..."
|
217
215
|
|
218
|
-
reader = HashReader.new(
|
216
|
+
reader = HashReader.new( path )
|
219
217
|
|
220
218
|
reader.each do |key, value|
|
221
219
|
country = Country.find_by_key!( key )
|
@@ -233,7 +231,7 @@ private
|
|
233
231
|
|
234
232
|
puts "*** parsing data '#{name}' (#{path})..."
|
235
233
|
|
236
|
-
reader = ValuesReader.new(
|
234
|
+
reader = ValuesReader.new( path, more_values )
|
237
235
|
|
238
236
|
load_fixtures_worker_for( clazz, reader )
|
239
237
|
|
@@ -323,7 +321,7 @@ private
|
|
323
321
|
value_numbers << value.gsub(/[ _]/, '').to_i
|
324
322
|
elsif (values.size==(index+1)) && value =~ /^[a-z0-9\|_ ]+$/ # tags must be last entry
|
325
323
|
|
326
|
-
|
324
|
+
logger.debug " found tags: >>#{value}<<"
|
327
325
|
|
328
326
|
tag_keys = value.split('|')
|
329
327
|
|
@@ -407,13 +405,13 @@ private
|
|
407
405
|
|
408
406
|
if rec.present?
|
409
407
|
## nb: [17..-1] cut off WorldDB::Models:: in name
|
410
|
-
|
408
|
+
logger.debug "update #{clazz.name[17..-1].downcase} #{rec.id}-#{rec.key}:"
|
411
409
|
else
|
412
|
-
|
410
|
+
logger.debug "create #{clazz.name[17..-1].downcase}:"
|
413
411
|
rec = clazz.new
|
414
412
|
end
|
415
413
|
|
416
|
-
|
414
|
+
logger.debug attribs.to_json
|
417
415
|
|
418
416
|
rec.update_attributes!( attribs )
|
419
417
|
|
@@ -429,9 +427,9 @@ private
|
|
429
427
|
## todo/fix: add country_id for lookup?
|
430
428
|
city = City.find_by_key( city_key )
|
431
429
|
if city.present?
|
432
|
-
|
430
|
+
logger.debug "update city #{city.id}-#{city.key}:"
|
433
431
|
else
|
434
|
-
|
432
|
+
logger.debug "create city:"
|
435
433
|
city = City.new
|
436
434
|
city_attribs[ :key ] = city_key
|
437
435
|
end
|
@@ -447,7 +445,7 @@ private
|
|
447
445
|
## issue warning: unknown type for city!!!
|
448
446
|
end
|
449
447
|
|
450
|
-
|
448
|
+
logger.debug city_attribs.to_json
|
451
449
|
|
452
450
|
city.update_attributes!( city_attribs )
|
453
451
|
|
@@ -462,14 +460,14 @@ private
|
|
462
460
|
if value_tag_keys.size > 0
|
463
461
|
|
464
462
|
value_tag_keys.uniq! # remove duplicates
|
465
|
-
|
463
|
+
logger.debug " adding #{value_tag_keys.size} taggings: >>#{value_tag_keys.join('|')}<<..."
|
466
464
|
|
467
465
|
### fix/todo: check tag_ids and only update diff (add/remove ids)
|
468
466
|
|
469
467
|
value_tag_keys.each do |key|
|
470
468
|
tag = Tag.find_by_key( key )
|
471
469
|
if tag.nil? # create tag if it doesn't exit
|
472
|
-
|
470
|
+
logger.debug " creating tag >#{key}<"
|
473
471
|
tag = Tag.create!( key: key )
|
474
472
|
end
|
475
473
|
rec.tags << tag
|
data/lib/worlddb/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worlddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-02-
|
18
|
+
date: 2013-02-22 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: textutils
|
@@ -25,12 +25,12 @@ dependencies:
|
|
25
25
|
requirements:
|
26
26
|
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 15
|
29
29
|
segments:
|
30
30
|
- 0
|
31
|
-
-
|
31
|
+
- 4
|
32
32
|
- 0
|
33
|
-
version: 0.
|
33
|
+
version: 0.4.0
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|