beerdb 0.8.1 → 0.8.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.
- data/Rakefile +3 -3
- data/bin/beerdb +0 -0
- data/lib/beerdb/cli/main.rb +170 -130
- data/lib/beerdb/cli/opts.rb +13 -4
- data/lib/beerdb/server.rb +9 -6
- data/lib/beerdb/version.rb +1 -1
- metadata +21 -19
data/Rakefile
CHANGED
@@ -26,11 +26,11 @@ Hoe.spec 'beerdb' do
|
|
26
26
|
# - logutils
|
27
27
|
# - textutils
|
28
28
|
|
29
|
-
|
30
|
-
['
|
29
|
+
## 3rd party
|
30
|
+
['gli', '>= 2.5.6']
|
31
31
|
]
|
32
32
|
|
33
|
-
|
33
|
+
self.licenses = ['Public Domain']
|
34
34
|
|
35
35
|
self.spec_extras = {
|
36
36
|
:required_ruby_version => '>= 1.9.2'
|
data/bin/beerdb
CHANGED
File without changes
|
data/lib/beerdb/cli/main.rb
CHANGED
@@ -1,37 +1,45 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'gli'
|
4
|
+
|
5
|
+
include GLI::App
|
6
|
+
|
4
7
|
|
5
8
|
require 'logutils/db' # add support for logging to db
|
6
9
|
require 'beerdb/cli/opts'
|
7
10
|
|
8
|
-
LogUtils::Logger.root.level = :info # set logging level to info
|
9
11
|
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
program :description, "beer.db command line tool, version #{BeerDb::VERSION}"
|
13
|
+
program_desc 'beer.db command line tool'
|
14
|
+
version BeerDb::VERSION
|
14
15
|
|
15
16
|
|
16
|
-
#
|
17
|
-
|
17
|
+
LogUtils::Logger.root.level = :info # set logging level to info
|
18
|
+
logger = LogUtils::Logger.root
|
18
19
|
|
19
|
-
program :help_formatter, Commander::HelpFormatter::TerminalCompact
|
20
20
|
|
21
|
+
opts = BeerDb::Opts.new
|
21
22
|
|
22
|
-
## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
|
23
|
-
myopts = BeerDb::Opts.new
|
24
23
|
|
25
24
|
### global option (required)
|
26
25
|
## todo: add check that path is valid?? possible?
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
desc 'Database path'
|
28
|
+
arg_name 'PATH'
|
29
|
+
default_value opts.db_path
|
30
|
+
flag [:d, :dbpath]
|
31
|
+
|
32
|
+
desc 'Database name'
|
33
|
+
arg_name 'NAME'
|
34
|
+
default_value opts.db_name
|
35
|
+
flag [:n, :dbname]
|
36
|
+
|
37
|
+
desc '(Debug) Show debug messages'
|
38
|
+
switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
|
39
|
+
|
40
|
+
desc 'Only show warnings, errors and fatal messages'
|
41
|
+
switch [:q, :quiet], negatable: false
|
31
42
|
|
32
|
-
global_option '-q', '--quiet', "Only show warnings, errors and fatal messages"
|
33
|
-
### todo/fix: just want --debug/--verbose flag (no single letter option wanted) - fix
|
34
|
-
global_option '-w', '--verbose', "Show debug messages"
|
35
43
|
|
36
44
|
|
37
45
|
def connect_to_db( options )
|
@@ -53,21 +61,17 @@ def connect_to_db( options )
|
|
53
61
|
end
|
54
62
|
|
55
63
|
|
56
|
-
|
57
|
-
|
58
|
-
c.description = 'Create DB schema'
|
64
|
+
desc 'Create DB schema'
|
65
|
+
command [:create] do |c|
|
59
66
|
|
60
|
-
c.
|
67
|
+
c.desc 'Extra tables (notes,drinks,marks,users)'
|
68
|
+
c.switch [:extras], negatable: false
|
61
69
|
|
62
|
-
c.action do |args
|
70
|
+
c.action do |g,o,args|
|
63
71
|
|
64
|
-
|
65
|
-
LogUtils::Logger.root.level = :debug if options.verbose.present?
|
72
|
+
connect_to_db( opts )
|
66
73
|
|
67
|
-
|
68
|
-
connect_to_db( myopts )
|
69
|
-
|
70
|
-
if options.extras.present?
|
74
|
+
if o[:extras].present?
|
71
75
|
# quick hack: only create extra tables
|
72
76
|
BeerDb::CreateDbExtrasUsers.new.up
|
73
77
|
BeerDb::CreateDbExtrasBookmarks.new.up
|
@@ -78,133 +82,139 @@ command :create do |c|
|
|
78
82
|
WorldDb.create
|
79
83
|
BeerDb.create
|
80
84
|
end
|
81
|
-
|
82
85
|
puts 'Done.'
|
83
86
|
end # action
|
84
87
|
end # command create
|
85
88
|
|
86
|
-
command :setup do |c|
|
87
|
-
c.syntax = 'beerdb setup [options]'
|
88
|
-
c.description = "Create DB schema 'n' load all data"
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
desc "Create DB schema 'n' load all world and beer data"
|
91
|
+
arg_name 'NAME' # optional setup profile name
|
92
|
+
command [:setup,:s] do |c|
|
93
93
|
|
94
|
-
c.
|
95
|
-
c.
|
94
|
+
c.desc 'Beer data path'
|
95
|
+
c.arg_name 'PATH'
|
96
|
+
c.default_value opts.data_path
|
97
|
+
c.flag [:i,:include]
|
96
98
|
|
97
|
-
c.
|
99
|
+
c.desc 'World data path'
|
100
|
+
c.arg_name 'PATH'
|
101
|
+
c.flag [:worldinclude] ## todo: use --world-include - how? find better name? add :'world-include' ???
|
98
102
|
|
99
|
-
|
100
|
-
LogUtils::Logger.root.level = :debug if options.verbose.present?
|
101
|
-
|
102
|
-
myopts.merge_commander_options!( options.__hash__ )
|
103
|
-
connect_to_db( myopts )
|
103
|
+
c.action do |g,o,args|
|
104
104
|
|
105
|
+
connect_to_db( opts )
|
106
|
+
|
105
107
|
## todo: document optional setup profile arg (defaults to all)
|
106
108
|
setup = args[0] || 'all'
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
# not really possible to delete world data if sport data is present
|
112
|
-
# delete sport first
|
113
|
-
|
114
|
-
if options.delete.present?
|
115
|
-
BeerDb.delete! if options.beer.present?
|
116
|
-
WorldDb.delete! if options.world.present?
|
117
|
-
end
|
118
|
-
|
119
|
-
if options.world.present?
|
120
|
-
WorldDb.read_all( myopts.world_data_path )
|
121
|
-
end
|
122
|
-
|
123
|
-
if options.beer.present?
|
124
|
-
BeerDb.read_setup( "setups/#{setup}", myopts.data_path )
|
125
|
-
end
|
126
|
-
|
127
|
-
else # assume "plain" regular setup
|
128
|
-
LogDb.create
|
129
|
-
WorldDb.create
|
130
|
-
BeerDb.create
|
110
|
+
LogDb.create
|
111
|
+
WorldDb.create
|
112
|
+
BeerDb.create
|
131
113
|
|
132
|
-
|
133
|
-
|
134
|
-
|
114
|
+
WorldDb.read_all( opts.world_data_path )
|
115
|
+
BeerDb.read_setup( "setups/#{setup}", opts.data_path )
|
116
|
+
puts 'Done.'
|
117
|
+
end # action
|
118
|
+
end # command setup
|
135
119
|
|
120
|
+
|
121
|
+
desc 'Update all beer data'
|
122
|
+
arg_name 'NAME' # optional setup profile name
|
123
|
+
command [:update,:up,:u] do |c|
|
124
|
+
|
125
|
+
c.desc 'Beer data path'
|
126
|
+
c.arg_name 'PATH'
|
127
|
+
c.default_value opts.data_path
|
128
|
+
c.flag [:i,:include]
|
129
|
+
|
130
|
+
c.desc 'Delete all beer data records'
|
131
|
+
c.switch [:delete], negatable: false
|
132
|
+
|
133
|
+
c.action do |g,o,args|
|
134
|
+
|
135
|
+
connect_to_db( opts )
|
136
|
+
|
137
|
+
## todo: document optional setup profile arg (defaults to all)
|
138
|
+
setup = args[0] || 'all'
|
139
|
+
|
140
|
+
BeerDb.delete! if o[:delete].present?
|
141
|
+
|
142
|
+
BeerDb.read_setup( "setups/#{setup}", opts.data_path )
|
136
143
|
puts 'Done.'
|
137
144
|
end # action
|
138
145
|
end # command setup
|
139
146
|
|
140
|
-
command :load do |c|
|
141
|
-
## todo: how to specify many fixutes <>... ??? in syntax
|
142
|
-
c.syntax = 'beerdb load [options] <fixtures>'
|
143
|
-
c.description = 'Load fixtures'
|
144
147
|
|
145
|
-
c.option '--delete', 'Delete all records'
|
146
148
|
|
147
|
-
|
149
|
+
desc 'Load beer fixtures'
|
150
|
+
arg_name 'NAME' # multiple fixture names - todo/fix: use multiple option
|
151
|
+
command [:load, :l] do |c|
|
148
152
|
|
149
|
-
|
150
|
-
|
153
|
+
c.desc 'Delete all beer data records'
|
154
|
+
c.switch [:delete], negatable: false
|
151
155
|
|
152
|
-
|
153
|
-
|
156
|
+
c.action do |g,o,args|
|
157
|
+
|
158
|
+
connect_to_db( opts )
|
154
159
|
|
155
|
-
if
|
156
|
-
|
157
|
-
|
158
|
-
end
|
160
|
+
BeerDb.delete! if o[:delete].present?
|
161
|
+
|
162
|
+
reader = BeerDb::Reader.new( opts.data_path )
|
159
163
|
|
160
|
-
# read plain text country/region/city fixtures
|
161
|
-
reader = BeerDb::Reader.new( myopts.data_path )
|
162
164
|
args.each do |arg|
|
163
165
|
name = arg # File.basename( arg, '.*' )
|
164
166
|
reader.load( name )
|
165
167
|
end # each arg
|
166
|
-
|
168
|
+
|
167
169
|
puts 'Done.'
|
168
170
|
end
|
169
171
|
end # command load
|
170
172
|
|
171
173
|
|
172
|
-
## fix/todo: add server alias (serve/server)
|
173
174
|
|
174
|
-
|
175
|
-
## todo: how to specify many fixutes <>... ??? in syntax
|
176
|
-
c.syntax = 'beerdb serve [options]'
|
177
|
-
c.description = 'Start web service (HTTP JSON API)'
|
175
|
+
## fix/todo: add server alias (serve/server)
|
178
176
|
|
179
|
-
|
177
|
+
desc 'Start web service (HTTP JSON API)'
|
178
|
+
command [:serve,:server] do |c|
|
180
179
|
|
181
|
-
|
182
|
-
LogUtils::Logger.root.level = :debug if options.verbose.present?
|
180
|
+
c.action do |g,o,args|
|
183
181
|
|
184
|
-
|
185
|
-
connect_to_db( myopts )
|
182
|
+
connect_to_db( opts )
|
186
183
|
|
187
184
|
# NB: server (HTTP service) not included in standard default require
|
188
185
|
require 'beerdb/server'
|
189
186
|
|
190
|
-
|
187
|
+
# make sure connections get closed after every request e.g.
|
188
|
+
#
|
189
|
+
# after do
|
190
|
+
# ActiveRecord::Base.connection.close
|
191
|
+
# end
|
192
|
+
#
|
193
|
+
|
194
|
+
puts 'before add middleware ConnectionManagement'
|
195
|
+
BeerDb::Server.use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
196
|
+
puts 'after add middleware ConnectionManagement'
|
197
|
+
## todo: check if we can check on/dump middleware stack
|
198
|
+
|
199
|
+
## rack middleware might not work with multi-threaded thin web server; close it ourselfs
|
200
|
+
BeerDb::Server.after do
|
201
|
+
puts " #{Thread.current.object_id} -- make sure db connections gets closed after request"
|
202
|
+
# todo: check if connection is open - how?
|
203
|
+
ActiveRecord::Base.connection.close
|
204
|
+
end
|
205
|
+
|
191
206
|
BeerDb::Server.run!
|
192
|
-
|
207
|
+
|
193
208
|
puts 'Done.'
|
194
209
|
end
|
195
|
-
end # command
|
210
|
+
end # command serve
|
196
211
|
|
197
212
|
|
213
|
+
desc 'Show stats'
|
198
214
|
command :stats do |c|
|
199
|
-
c.
|
200
|
-
c.description = 'Show stats'
|
201
|
-
c.action do |args, options|
|
202
|
-
|
203
|
-
LogUtils::Logger.root.level = :warn if options.quiet.present?
|
204
|
-
LogUtils::Logger.root.level = :debug if options.verbose.present?
|
215
|
+
c.action do |g,o,args|
|
205
216
|
|
206
|
-
|
207
|
-
connect_to_db( myopts )
|
217
|
+
connect_to_db( opts )
|
208
218
|
|
209
219
|
BeerDb.tables
|
210
220
|
|
@@ -213,16 +223,11 @@ command :stats do |c|
|
|
213
223
|
end
|
214
224
|
|
215
225
|
|
226
|
+
desc 'Show props'
|
216
227
|
command :props do |c|
|
217
|
-
c.
|
218
|
-
c.description = 'Show props'
|
219
|
-
c.action do |args, options|
|
228
|
+
c.action do |g,o,args|
|
220
229
|
|
221
|
-
|
222
|
-
LogUtils::Logger.root.level = :debug if options.verbose.present?
|
223
|
-
|
224
|
-
myopts.merge_commander_options!( options.__hash__ )
|
225
|
-
connect_to_db( myopts )
|
230
|
+
connect_to_db( opts )
|
226
231
|
|
227
232
|
BeerDb.props
|
228
233
|
|
@@ -230,17 +235,11 @@ command :props do |c|
|
|
230
235
|
end
|
231
236
|
end
|
232
237
|
|
233
|
-
|
238
|
+
desc 'Show logs'
|
234
239
|
command :logs do |c|
|
235
|
-
c.
|
236
|
-
c.description = 'Show logs'
|
237
|
-
c.action do |args, options|
|
240
|
+
c.action do |g,o,args|
|
238
241
|
|
239
|
-
|
240
|
-
LogUtils::Logger.root.level = :debug if options.verbose.present?
|
241
|
-
|
242
|
-
myopts.merge_commander_options!( options.__hash__ )
|
243
|
-
connect_to_db( myopts )
|
242
|
+
connect_to_db( opts )
|
244
243
|
|
245
244
|
LogDb::Models::Log.all.each do |log|
|
246
245
|
puts "[#{log.level}] -- #{log.msg}"
|
@@ -252,17 +251,58 @@ end
|
|
252
251
|
|
253
252
|
|
254
253
|
|
254
|
+
desc '(Debug) Test command suite'
|
255
255
|
command :test do |c|
|
256
|
-
c.
|
257
|
-
|
258
|
-
c.action do |args, options|
|
256
|
+
c.action do |g,o,args|
|
257
|
+
|
259
258
|
puts "hello from test command"
|
260
259
|
puts "args (#{args.class.name}):"
|
261
260
|
pp args
|
262
|
-
puts "
|
263
|
-
pp
|
264
|
-
puts "
|
265
|
-
pp
|
261
|
+
puts "o (#{o.class.name}):"
|
262
|
+
pp o
|
263
|
+
puts "g (#{g.class.name}):"
|
264
|
+
pp g
|
265
|
+
|
266
|
+
LogUtils::Logger.root.debug 'test debug msg'
|
267
|
+
LogUtils::Logger.root.info 'test info msg'
|
268
|
+
LogUtils::Logger.root.warn 'test warn msg'
|
269
|
+
|
266
270
|
puts 'Done.'
|
267
271
|
end
|
268
272
|
end
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
pre do |g,c,o,args|
|
277
|
+
opts.merge_gli_options!( g )
|
278
|
+
opts.merge_gli_options!( o )
|
279
|
+
|
280
|
+
puts BeerDb.banner
|
281
|
+
|
282
|
+
if opts.verbose?
|
283
|
+
LogUtils::Logger.root.level = :debug
|
284
|
+
end
|
285
|
+
|
286
|
+
logger.debug "Executing #{c.name}"
|
287
|
+
true
|
288
|
+
end
|
289
|
+
|
290
|
+
post do |global,c,o,args|
|
291
|
+
logger.debug "Executed #{c.name}"
|
292
|
+
true
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
on_error do |e|
|
297
|
+
puts
|
298
|
+
puts "*** error: #{e.message}"
|
299
|
+
|
300
|
+
if opts.verbose?
|
301
|
+
puts e.backtrace
|
302
|
+
end
|
303
|
+
|
304
|
+
false # skip default error handling
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
exit run(ARGV)
|
data/lib/beerdb/cli/opts.rb
CHANGED
@@ -2,17 +2,26 @@ module BeerDb
|
|
2
2
|
|
3
3
|
class Opts
|
4
4
|
|
5
|
-
|
6
|
-
def merge_commander_options!( options = {} )
|
5
|
+
def merge_gli_options!( options = {} )
|
7
6
|
@db_path = options[:dbpath] if options[:dbpath].present?
|
8
7
|
@db_name = options[:dbname] if options[:dbname].present?
|
9
8
|
|
10
|
-
@
|
11
|
-
|
9
|
+
@verbose = true if options[:verbose] == true
|
10
|
+
|
11
|
+
@data_path = options[:include] if options[:include].present?
|
12
12
|
@world_data_path = options[:worldinclude] if options[:worldinclude].present?
|
13
13
|
end
|
14
14
|
|
15
15
|
|
16
|
+
def verbose=(boolean) # add: alias for debug ??
|
17
|
+
@verbose = boolean
|
18
|
+
end
|
19
|
+
|
20
|
+
def verbose?
|
21
|
+
return false if @verbose.nil? # default verbose/debug flag is false
|
22
|
+
@verbose == true
|
23
|
+
end
|
24
|
+
|
16
25
|
|
17
26
|
def db_path
|
18
27
|
@db_path || '.'
|
data/lib/beerdb/server.rb
CHANGED
@@ -45,12 +45,15 @@ class Server < Sinatra::Base
|
|
45
45
|
|
46
46
|
##################
|
47
47
|
# Helpers
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
#
|
49
|
+
# NB: helpers are just instance methods! no need in modular apps to use
|
50
|
+
# helpers do
|
51
|
+
# <code>
|
52
|
+
# end
|
53
|
+
|
54
|
+
def path_prefix
|
55
|
+
request.env['SCRIPT_NAME']
|
56
|
+
end
|
54
57
|
|
55
58
|
##############################################
|
56
59
|
# Controllers / Routing / Request Handlers
|
data/lib/beerdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beerdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-17 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &19996224 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19996224
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: worlddb
|
27
|
-
requirement: &
|
27
|
+
requirement: &19995804 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,47 +32,49 @@ dependencies:
|
|
32
32
|
version: '1.7'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19995804
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
37
|
+
name: gli
|
38
|
+
requirement: &19995360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 2.5.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19995360
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &19995060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4.0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *19995060
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: hoe
|
60
|
-
requirement: &
|
60
|
+
requirement: &19994712 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: '3.
|
65
|
+
version: '3.6'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *19994712
|
69
69
|
description: beerdb - beer.db command line tool
|
70
70
|
email: beerdb@googlegroups.com
|
71
71
|
executables:
|
72
72
|
- beerdb
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files:
|
75
|
+
- History.md
|
75
76
|
- Manifest.txt
|
77
|
+
- README.md
|
76
78
|
files:
|
77
79
|
- History.md
|
78
80
|
- Manifest.txt
|
@@ -136,10 +138,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
138
|
version: '0'
|
137
139
|
requirements: []
|
138
140
|
rubyforge_project: beerdb
|
139
|
-
rubygems_version: 1.
|
141
|
+
rubygems_version: 1.7.2
|
140
142
|
signing_key:
|
141
143
|
specification_version: 3
|
142
144
|
summary: beerdb - beer.db command line tool
|
143
145
|
test_files:
|
144
|
-
- test/test_values.rb
|
145
146
|
- test/test_fixture_matchers.rb
|
147
|
+
- test/test_values.rb
|