worlddb 2.3.0 → 2.4.0

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: 24d659b0a6e54a1035ee66d2a01ab34766703d09
4
- data.tar.gz: c813625ec34d148179e5950346b415a791729f11
3
+ metadata.gz: 5409171705fa17c821d82dacaaedd35c511cb655
4
+ data.tar.gz: a821bfda1ff817abb8c528a5c94c2394a610d0e5
5
5
  SHA512:
6
- metadata.gz: ff6dfd3b729c340fc7bf63050d87ac4dd72c5def886f9ae03626a8c71753228b359b3ad4378cdc6a48e4fe22c66c4228971284f08b0423f4d0837365833701a3
7
- data.tar.gz: 2af456f08c297e815dcdc5faa3b737b6676a770f78016dd8959764b2306da522c8096da32899a1b399278a1fd2ea2c225fa973421a40c812ed96a92f25421aba
6
+ metadata.gz: 6ba8eff38e8715905a39ca1ca321b3d6eae33bb5a497d264ed744c277b533075493d794de0cddd51a703ff68fdc4ce752591453d83ad9a5174dfd6b9494f3000
7
+ data.tar.gz: 2871b28c04af9277cea4fec82ca1a8fb3261b49772f4cb372d0681a63d14deb27616f743466c9afc94719ad15d6167fd6a61a9702d6601febf87b7b78fca0dd9
@@ -1,10 +1,11 @@
1
- HISTORY.md
2
- Manifest.txt
3
- README.md
4
- Rakefile
5
- bin/worlddb
6
- lib/worlddb.rb
7
- lib/worlddb/cli/main.rb
8
- lib/worlddb/cli/opts.rb
9
- lib/worlddb/cli/version.rb
10
- lib/worlddb/console.rb
1
+ HISTORY.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ assets/webservice-worlddb-32x32.png
6
+ bin/worlddb
7
+ lib/worlddb.rb
8
+ lib/worlddb/cli/main.rb
9
+ lib/worlddb/cli/opts.rb
10
+ lib/worlddb/cli/version.rb
11
+ lib/worlddb/console.rb
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # worlddb
2
2
 
3
- world.db Command Line Tool in Ruby
3
+ world.db Command Line Tool
4
4
 
5
- * home :: [github.com/worlddb/world.db.tools](https://github.com/worlddb/world.db.tools)
6
- * bugs :: [github.com/worlddb/world.db.tools/issues](https://github.com/worlddb/world.db.tools/issues)
5
+ * home :: [github.com/worlddb/world.db](https://github.com/worlddb/world.db)
6
+ * bugs :: [github.com/worlddb/world.db/issues](https://github.com/worlddb/world.db/issues)
7
7
  * gem :: [rubygems.org/gems/worlddb](https://rubygems.org/gems/worlddb)
8
8
  * rdoc :: [rubydoc.info/gems/worlddb](http://rubydoc.info/gems/worlddb)
9
9
  * forum :: [groups.google.com/group/openmundi](https://groups.google.com/group/openmundi)
@@ -12,9 +12,9 @@ world.db Command Line Tool in Ruby
12
12
  ## Usage Command Line
13
13
 
14
14
  The worlddb gem lets you load plain text fixtures into your database
15
- (and also includes schema n models for easy reuse).
15
+ (and also includes schema n models for easy reuse).
16
16
 
17
- ~~~
17
+ ```
18
18
  SYNOPSIS
19
19
  worlddb [global options] command [command options] [arguments...]
20
20
 
@@ -37,12 +37,12 @@ COMMANDS
37
37
  stats - Show stats
38
38
  test - (Debug) Test command suite
39
39
  help - Shows a list of commands or help for one command
40
- ~~~
40
+ ```
41
41
 
42
42
 
43
43
  ### `setup` Command
44
44
 
45
- ~~~
45
+ ```
46
46
  NAME
47
47
  setup - Create DB schema 'n' load all world data
48
48
 
@@ -55,12 +55,12 @@ COMMAND OPTIONS
55
55
  EXAMPLES
56
56
  worlddb setup --include ./world.db
57
57
  worlddb setup us --include ./world.db
58
- ~~~
58
+ ```
59
59
 
60
60
 
61
61
  ### `update` Command
62
62
 
63
- ~~~
63
+ ```
64
64
  NAME
65
65
  update - Update all world data
66
66
 
@@ -74,12 +74,12 @@ COMMAND OPTIONS
74
74
  EXAMPLES
75
75
  worlddb update --include ./world.db
76
76
  worlddb update --include ./world.db --delete
77
- ~~~
77
+ ```
78
78
 
79
79
 
80
80
  ### `load` Command
81
81
 
82
- ~~~
82
+ ```
83
83
  NAME
84
84
  load - Load world fixtures
85
85
 
@@ -92,7 +92,7 @@ COMMAND OPTIONS
92
92
 
93
93
  EXAMPLES
94
94
  worlddb load --include ./world.db europe/countries
95
- ~~~
95
+ ```
96
96
 
97
97
 
98
98
  ## Install
@@ -102,13 +102,11 @@ Just install the gem:
102
102
  $ gem install worlddb
103
103
 
104
104
 
105
- ## Free Open Public Domain Datasets
106
-
107
- - [`world.db`](https://github.com/openmundi) - free open public domain countries, regions, cities n more data for use in any (programming) language
108
-
109
105
 
110
106
  ## License
111
107
 
108
+ ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
109
+
112
110
  The `worlddb` scripts are dedicated to the public domain.
113
111
  Use it as you please with no restrictions whatsoever.
114
112
 
data/Rakefile CHANGED
@@ -3,21 +3,22 @@ require './lib/worlddb/cli/version.rb'
3
3
 
4
4
 
5
5
  Hoe.spec 'worlddb' do
6
-
7
- self.version = WorldDbCli::VERSION
6
+
7
+ self.version = WorldDbTool::VERSION
8
8
 
9
9
  self.summary = "worlddb - world.db command line tool"
10
10
  self.description = summary
11
11
 
12
- self.urls = ['https://github.com/worlddb/world.db.tools']
12
+ self.urls = ['https://github.com/worlddb/world.db']
13
13
 
14
14
  self.author = 'Gerald Bauer'
15
15
  self.email = 'openmundi@googlegroups.com'
16
16
 
17
17
  self.extra_deps = [
18
- ['worlddb-models', '>=2.3.0'],
18
+ ['worlddb-models', '>=2.4.0'],
19
19
  ### ['worlddb-service'],
20
20
 
21
+ ['webservice', '>=0.6.1'],
21
22
  ['datafile', '>= 0.2.2'],
22
23
  ['fetcher', '>= 0.4.5'],
23
24
 
@@ -35,7 +36,7 @@ Hoe.spec 'worlddb' do
35
36
  self.licenses = ['Public Domain']
36
37
 
37
38
  self.spec_extras = {
38
- required_ruby_version: '>= 1.9.2'
39
+ required_ruby_version: '>= 2.3'
39
40
  }
40
41
 
41
42
  end
File without changes
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'worlddb/models' # NOTE: depends on core (aka worlddb-models)
3
+ require 'worlddb/models' # Note: depends on core (aka worlddb-models)
4
+
5
+ require 'webservice'
4
6
 
5
7
  require 'fetcher'
6
8
  require 'datafile'
@@ -24,4 +26,61 @@ module WorldDb
24
26
  end # module WorldDb
25
27
 
26
28
 
29
+
30
+ ####
31
+ ## used for server/service command
32
+ ## "preconfigured" base class for webservice
33
+ class WorldDbService < Webservice::Base
34
+ include WorldDb::Models # e.g. Continent, Country, State, City, etc.
35
+
36
+ ## (auto-)add some (built-in) routes
37
+
38
+ get '/version(s)?' do
39
+ {
40
+ "worlddb": WorldDbTool::VERSION,
41
+ "worlddb/models": WorldDb::VERSION,
42
+ ## todo/fix: add some more libs - why? why not??
43
+ "activerecord": [ActiveRecord::VERSION::MAJOR,ActiveRecord::VERSION::MINOR,ActiveRecord::VERSION::TINY].join('.'),
44
+ "webservice": Webservice::VERSION,
45
+ "rack": "#{Rack::RELEASE} (#{Rack::VERSION.join('.')})", ## note: VERSION is the protocoll version as an array e.g.[1,2]
46
+ "ruby": "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]",
47
+ }
48
+ end
49
+
50
+ get '/(stats|tables)' do
51
+ {
52
+ "countries": WorldDb::Model::Country.count,
53
+ "states": WorldDb::Model::State.count,
54
+ "cities": WorldDb::Model::City.count,
55
+ "system": {
56
+ "props": ConfDb::Models::Prop.count,
57
+ "logs": LogDb::Models::Log.count,
58
+ }
59
+ }
60
+ end
61
+
62
+ get '/props(.:format)?' do # note: add format - lets you use props.csv and props.html
63
+ ConfDb::Models::Prop.all
64
+ end
65
+
66
+ get '/logs(.:format)?' do
67
+ LogDb::Models::Log.all
68
+ end
69
+
70
+
71
+ ## add favicon support
72
+ get '/favicon.ico' do
73
+ ## use 302 to redirect
74
+ ## note: use strg+F5 to refresh page (clear cache for favicon.ico)
75
+ redirect '/webservice-worlddb-32x32.png'
76
+ end
77
+
78
+ get '/webservice-worlddb-32x32.png' do
79
+ send_file "#{WorldDbTool.root}/assets/webservice-worlddb-32x32.png"
80
+ end
81
+
82
+ end # class WorldDbService
83
+
84
+
85
+
27
86
  WorldDb.main if __FILE__ == $0
@@ -8,11 +8,11 @@ module WorldDb
8
8
 
9
9
  class Tool
10
10
  def initialize
11
- LogUtils::Logger.root.level = :info # set logging level to info
11
+ LogUtils::Logger.root.level = :info # set logging level to info
12
12
  end
13
13
 
14
14
  def run( args )
15
- puts WorldDbCli.banner
15
+ puts WorldDbTool.banner
16
16
  Toolii.run( args )
17
17
  end
18
18
  end
@@ -38,12 +38,12 @@ module WorldDb
38
38
  end
39
39
 
40
40
  logger = LogUtils::Logger.root
41
- opts = WorldDb::Opts.new
41
+ opts = WorldDb::Opts.new
42
42
 
43
43
 
44
44
  program_desc 'world.db command line tool'
45
45
 
46
- version WorldDbCli::VERSION
46
+ version WorldDbTool::VERSION
47
47
 
48
48
  =begin
49
49
  ### add to help use new sections
@@ -86,7 +86,7 @@ command [:build,:b] do |c|
86
86
  c.action do |g,o,args|
87
87
 
88
88
  datafile = Datafile::Datafile.load_file( './Datafile' )
89
- datafile.download # datafile step 1 - download all datasets/zips
89
+ datafile.download # datafile step 1 - download all datasets/zips
90
90
 
91
91
  connect_to_db( opts )
92
92
 
@@ -142,7 +142,7 @@ command [:new,:n] do |c|
142
142
 
143
143
  ## step 2: same as command build (todo - reuse code)
144
144
  datafile = Datafile::Datafile.load_file( './Datafile' )
145
- datafile.download # datafile step 1 - download all datasets/zips
145
+ datafile.download # datafile step 1 - download all datasets/zips
146
146
 
147
147
  connect_to_db( opts ) ### todo: check let connect go first?? - for logging (logs) to db ???
148
148
 
@@ -159,9 +159,9 @@ end # command setup
159
159
  desc 'Create DB schema'
160
160
  command [:create] do |c|
161
161
  c.action do |g,o,args|
162
-
162
+
163
163
  connect_to_db( opts )
164
-
164
+
165
165
  WorldDb.create_all
166
166
 
167
167
  puts 'Done.'
@@ -180,10 +180,10 @@ command [:setup,:s] do |c|
180
180
  c.action do |g,o,args|
181
181
 
182
182
  connect_to_db( opts )
183
-
183
+
184
184
  ## todo: document optional setup profile arg (defaults to all)
185
185
  setup = args[0] || 'all'
186
-
186
+
187
187
  WorldDb.create_all
188
188
 
189
189
  WorldDb.read_setup( "setups/#{setup}", opts.data_path )
@@ -234,7 +234,7 @@ command [:load, :l] do |c|
234
234
  c.action do |g,o,args|
235
235
 
236
236
  connect_to_db( opts )
237
-
237
+
238
238
  if o[:delete].present?
239
239
  ## todo/fix: also delete TagDb.delete!
240
240
  WorldDb.delete!
@@ -271,9 +271,11 @@ command :props do |c|
271
271
  c.action do |g,o,args|
272
272
 
273
273
  connect_to_db( opts )
274
-
274
+
275
275
  ### fix: use ConfDb.dump or similar (for reuse) !!!
276
- ## WorldDb.props
276
+ ConfDb::Models::Prop.all.each do |prop|
277
+ puts "#{prop.key} | #{prop.value}"
278
+ end
277
279
 
278
280
  puts 'Done.'
279
281
  end
@@ -286,16 +288,57 @@ command :logs do |c|
286
288
 
287
289
  connect_to_db( opts )
288
290
 
289
- ### fix: use LogDb.dump or similar (for reuse) !!!!
291
+ ### fix: use LogDb.dump or similar (for reuse) !!!!
290
292
  LogDb::Models::Log.all.each do |log|
291
293
  puts "[#{log.level}] -- #{log.msg}"
292
294
  end
293
-
295
+
294
296
  puts 'Done.'
295
297
  end
296
298
  end
297
299
 
298
300
 
301
+
302
+ desc 'Start web service (HTTP JSON API)'
303
+ arg_name 'NAME' # optional setup profile name
304
+ command [:serve,:server,:s] do |c|
305
+
306
+ c.action do |g,o,args|
307
+
308
+ ## todo: document optional script arg (defaults to service)
309
+ script = args[0] || 'service'
310
+
311
+ ## todo/fix: add support for (default) Service (with no extension)
312
+
313
+ script_path = "#{script}.rb" ## auto-add .rb extension
314
+
315
+ unless File.exist?( script_path ) ## if file doesn't exist try to fetch service script
316
+ script_path = "./#{script}.rb" ## use / save script in local (current) working dir/folder
317
+ worker = Fetcher::Worker.new
318
+ ## note: lets use http:// instead of https:// for now - lets us use person proxy (NOT working w/ https for now)
319
+ worker.copy( "http://github.com/worlddb/world.db.service/raw/master/#{script}.rb", script_path )
320
+ end
321
+
322
+
323
+ code = File.read_utf8( script_path )
324
+
325
+ connect_to_db( opts )
326
+
327
+ WorldDb.tables ## print table stats
328
+
329
+ WorldDbService.class_eval( code ) ## note: MUST use class_eval (do NOT use instance_eval) !!!
330
+
331
+ puts "dump routes:"
332
+ pp WorldDbService.routes
333
+
334
+ puts "starting server..."
335
+ WorldDbService.run!
336
+
337
+ puts 'Done.'
338
+ end
339
+ end # command serve
340
+
341
+
299
342
  desc '(Debug) Test command suite'
300
343
  command :test do |c|
301
344
  c.action do |g,o,args|
@@ -307,11 +350,11 @@ command :test do |c|
307
350
  pp o
308
351
  puts "g (#{g.class.name}):"
309
352
  pp g
310
-
353
+
311
354
  LogUtils::Logger.root.debug 'test debug msg'
312
355
  LogUtils::Logger.root.info 'test info msg'
313
356
  LogUtils::Logger.root.warn 'test warn msg'
314
-
357
+
315
358
  puts 'Done.'
316
359
  end
317
360
  end
@@ -351,4 +394,3 @@ end
351
394
 
352
395
  end # class Toolii
353
396
  end # module WorldDb
354
-
@@ -3,10 +3,10 @@
3
3
  # Note: WorldDb::VERSION gets used by core, that is, worlddb-models
4
4
 
5
5
 
6
- module WorldDbCli # todo/check - rename to WorldDbTool or WorldDbCommands or WorldDbShell ??
6
+ module WorldDbTool # todo/check - rename to WorldDbTool or WorldDbCommands or WorldDbShell ??
7
7
 
8
8
  MAJOR = 2 ## todo: namespace inside version or something - why? why not??
9
- MINOR = 3
9
+ MINOR = 4
10
10
  PATCH = 0
11
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
12
12
 
@@ -22,4 +22,4 @@ module WorldDbCli # todo/check - rename to WorldDbTool or WorldDbCommands or
22
22
  "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
23
23
  end
24
24
 
25
- end # module WorldDbCli
25
+ end # module WorldDbTool
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.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-08 00:00:00.000000000 Z
11
+ date: 2017-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: worlddb-models
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.0
19
+ version: 2.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.0
26
+ version: 2.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: webservice
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: datafile
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '3.13'
117
+ version: '3.16'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '3.13'
124
+ version: '3.16'
111
125
  description: worlddb - world.db command line tool
112
126
  email: openmundi@googlegroups.com
113
127
  executables:
@@ -122,13 +136,14 @@ files:
122
136
  - Manifest.txt
123
137
  - README.md
124
138
  - Rakefile
139
+ - assets/webservice-worlddb-32x32.png
125
140
  - bin/worlddb
126
141
  - lib/worlddb.rb
127
142
  - lib/worlddb/cli/main.rb
128
143
  - lib/worlddb/cli/opts.rb
129
144
  - lib/worlddb/cli/version.rb
130
145
  - lib/worlddb/console.rb
131
- homepage: https://github.com/worlddb/world.db.tools
146
+ homepage: https://github.com/worlddb/world.db
132
147
  licenses:
133
148
  - Public Domain
134
149
  metadata: {}
@@ -142,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
157
  requirements:
143
158
  - - ">="
144
159
  - !ruby/object:Gem::Version
145
- version: 1.9.2
160
+ version: '2.3'
146
161
  required_rubygems_version: !ruby/object:Gem::Requirement
147
162
  requirements:
148
163
  - - ">="
@@ -150,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
165
  version: '0'
151
166
  requirements: []
152
167
  rubyforge_project:
153
- rubygems_version: 2.4.2
168
+ rubygems_version: 2.5.2
154
169
  signing_key:
155
170
  specification_version: 4
156
171
  summary: worlddb - world.db command line tool