beerdb 0.9.13 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd5af8feb16a5a25aac740c6cc34a08aec1109b6
4
+ data.tar.gz: dd4b95c41c8a89754e9f3c864234ba00758f8437
5
+ SHA512:
6
+ metadata.gz: 37052c2727905e75c047d20ef2c8f300f58523102108ae6a670e3d945debbfa820c78b329135d308659714f999f970dc1eba6121fd5080be9383e97edecee28a
7
+ data.tar.gz: 9db94348d1f538e861c927eec9edc8358cf0cca72d43435d36f297f6eb7a3311e20c05aee1b15e5df81c32fd4f7edd8a4e82b9e9f88cdb9c54842ade45e7e31c
data/HISTORY.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.1.0 / 2014-12-07
2
+
3
+ * Everything is new. First release
data/Manifest.txt CHANGED
@@ -1,4 +1,4 @@
1
- History.md
1
+ HISTORY.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
@@ -6,24 +6,5 @@ bin/beerdb
6
6
  lib/beerdb.rb
7
7
  lib/beerdb/cli/main.rb
8
8
  lib/beerdb/cli/opts.rb
9
+ lib/beerdb/cli/version.rb
9
10
  lib/beerdb/console.rb
10
- lib/beerdb/deleter.rb
11
- lib/beerdb/models/beer.rb
12
- lib/beerdb/models/brand.rb
13
- lib/beerdb/models/brewery.rb
14
- lib/beerdb/models/forward.rb
15
- lib/beerdb/models/tag.rb
16
- lib/beerdb/models/world/city.rb
17
- lib/beerdb/models/world/country.rb
18
- lib/beerdb/models/world/region.rb
19
- lib/beerdb/reader.rb
20
- lib/beerdb/reader_file.rb
21
- lib/beerdb/reader_zip.rb
22
- lib/beerdb/schema.rb
23
- lib/beerdb/serializers/beer.rb
24
- lib/beerdb/serializers/brewery.rb
25
- lib/beerdb/stats.rb
26
- lib/beerdb/version.rb
27
- test/helper.rb
28
- test/test_fixture_matchers.rb
29
- test/test_values.rb
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
- # beerdb
1
+ # beerdb gem - open beer database (beer.db) command line tool in ruby
2
2
 
3
- beer.db Command Line Tool in Ruby
4
3
 
5
4
  * home :: [github.com/beerkit/beer.db.ruby](https://github.com/beerkit/beer.db.ruby)
6
5
  * bugs :: [github.com/beerkit/beer.db.ruby/issues](https://github.com/beerkit/beer.db.ruby/issues)
@@ -35,82 +34,6 @@ beer.db Command Line Tool in Ruby
35
34
  -t, --trace Display backtrace when an error occurs
36
35
 
37
36
 
38
- ## Usage Models
39
-
40
- Brewery Model
41
-
42
- ```
43
- by = Brewery.find_by_key( 'guinness' )
44
-
45
- by.title
46
- => 'St. James's Gate Brewery / Guinness Brewery'
47
-
48
- by.country.key
49
- => 'ie'
50
-
51
- by.country.title
52
- => 'Ireland'
53
-
54
- by.city.title
55
- => 'Dublin'
56
-
57
- by.beers.first
58
- => 'Guinness', 4.2
59
-
60
- ...
61
- ```
62
-
63
-
64
- Beer Model
65
-
66
- ```
67
- b = Beer.find_by_key( 'guinness' )
68
-
69
- b.title
70
- => 'Guinness'
71
-
72
- b.abv
73
- => 4.2
74
-
75
- b.tags
76
- => 'irish_dry_stout', 'dry_stout', 'stout'
77
-
78
- b.brewery.title
79
- => 'St. James's Gate Brewery / Guinness Brewery'
80
-
81
- ...
82
- ```
83
-
84
-
85
- Country Model
86
-
87
- ```
88
- at = Country.find_by_key( 'at' )
89
-
90
- at.beers
91
- => 'Weitra Helles', 'Hadmar', 'Zwettler Original', ...
92
-
93
- at.breweries
94
- => 'Weitra Bräu Bierwerkstatt', 'Zwettler Brauerei', ...
95
-
96
- ...
97
- ```
98
-
99
-
100
- City Model
101
-
102
- ```
103
- wien = City.find_by_key( 'wien' )
104
-
105
- wien.beers
106
- => 'Ottakringer Helles', 'Ottakringer (Gold Fassl) Zwickl', ...
107
-
108
- wien.breweries
109
- => 'Ottakringer Brauerei'
110
-
111
- ...
112
- ```
113
-
114
37
 
115
38
  ## Install
116
39
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'hoe'
2
- require './lib/beerdb/version.rb'
2
+ require './lib/beerdb/cli/version.rb'
3
3
 
4
4
 
5
5
  Hoe.spec 'beerdb' do
6
-
7
- self.version = BeerDb::VERSION
8
-
6
+
7
+ self.version = BeerDbCli::VERSION
8
+
9
9
  self.summary = 'beerdb - beer.db command line tool'
10
10
  self.description = summary
11
11
 
@@ -16,32 +16,23 @@ Hoe.spec 'beerdb' do
16
16
 
17
17
  # switch extension to .markdown for gihub formatting
18
18
  self.readme_file = 'README.md'
19
- self.history_file = 'History.md'
19
+ self.history_file = 'HISTORY.md'
20
20
 
21
21
  self.extra_deps = [
22
- ['props' ],
23
- ['logutils'],
24
- ['textutils'],
25
- ['worlddb', '>= 2.0.2'], # NB: worlddb already includes
26
- # - logutils
27
- # - textutils
28
- ['tagutils'], # tags n tagging tables
29
- ['activerecord-utils'], # extras e.g. rnd, find_by! for 3.x etc.
30
- ['fetcher', '>= 0.3'],
22
+ ['beerdb-models', '>= 0.10.0'],
31
23
 
32
- ## 3rd party
33
- ['gli', '>= 2.5.6'],
24
+ ['datafile', '>= 0.1.1'],
25
+ ['fetcher', '>= 0.4.4'],
34
26
 
35
- ['rubyzip'], ## NOTE: used for ZipReader (optional in textutils, thus, pull it in here)
36
-
37
- ['activerecord'] # NB: will include activesupport,etc.
38
- ### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
27
+ ## 3rd party
28
+ ['gli', '>= 2.12.2'],
29
+ ['sqlite3']
39
30
  ]
40
31
 
41
32
  self.licenses = ['Public Domain']
42
33
 
43
34
  self.spec_extras = {
44
- :required_ruby_version => '>= 1.9.2'
35
+ required_ruby_version: '>= 1.9.2'
45
36
  }
46
37
 
47
38
  end
@@ -1,24 +1,58 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'gli'
4
-
5
- include GLI::App
3
+ ### NOTE: wrap gli config into a class
4
+ ## see github.com/davetron5000/gli/issues/153
6
5
 
7
6
 
8
- require 'logutils/db' # add support for logging to db
9
- require 'beerdb/cli/opts'
7
+ module BeerDb
10
8
 
9
+ class Tool
10
+ def initialize
11
+ LogUtils::Logger.root.level = :info # set logging level to info
12
+ end
11
13
 
14
+ def run( args )
15
+ puts BeerDbCli.banner
16
+ Toolii.run( args )
17
+ end
18
+ end
19
+
20
+
21
+ class Toolii
22
+ extend GLI::App
23
+
24
+ def self.logger=(value) @@logger=value; end
25
+ def self.logger() @@logger; end
26
+
27
+ ## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
28
+ def self.opts=(value) @@opts = value; end
29
+ def self.opts() @@opts; end
30
+
31
+ def self.connect_to_db( options )
32
+ puts "working directory: #{Dir.pwd}"
33
+
34
+ db_config = {
35
+ adapter: 'sqlite3',
36
+ database: "#{options.db_path}/#{options.db_name}"
37
+ }
38
+
39
+ puts "Connecting to db using settings: "
40
+ pp db_config
41
+
42
+ ActiveRecord::Base.establish_connection( db_config )
43
+
44
+ LogDb.setup # start logging to db (that is, save logs in logs table in db)
45
+ end
12
46
 
13
- program_desc 'beer.db command line tool'
14
- version BeerDb::VERSION
15
47
 
16
48
 
17
- LogUtils::Logger.root.level = :info # set logging level to info
18
49
  logger = LogUtils::Logger.root
50
+ opts = BeerDb::Opts.new
19
51
 
20
52
 
21
- opts = BeerDb::Opts.new
53
+
54
+ program_desc 'beer.db command line tool'
55
+ version BeerDbCli::VERSION
22
56
 
23
57
 
24
58
  ### global option (required)
@@ -42,25 +76,6 @@ switch [:q, :quiet], negatable: false
42
76
 
43
77
 
44
78
 
45
- def connect_to_db( options )
46
- puts BeerDb.banner
47
-
48
- puts "working directory: #{Dir.pwd}"
49
-
50
- db_config = {
51
- :adapter => 'sqlite3',
52
- :database => "#{options.db_path}/#{options.db_name}"
53
- }
54
-
55
- puts "Connecting to db using settings: "
56
- pp db_config
57
-
58
- ActiveRecord::Base.establish_connection( db_config )
59
-
60
- LogDb.setup # turn on logging to db
61
- end
62
-
63
-
64
79
  desc 'Create DB schema'
65
80
  command [:create] do |c|
66
81
 
@@ -78,11 +93,7 @@ command [:create] do |c|
78
93
  BeerDb::CreateDbExtrasNotes.new.up
79
94
  BeerDb::CreateDbExtrasDrinks.new.up
80
95
  else
81
- LogDb.create
82
- ConfDb.create
83
- TagDb.create
84
- WorldDb.create
85
- BeerDb.create
96
+ BeerDb.create_all
86
97
  end
87
98
  puts 'Done.'
88
99
  end # action
@@ -109,11 +120,7 @@ command [:setup,:s] do |c|
109
120
  ## todo: document optional setup profile arg (defaults to all)
110
121
  setup = args[0] || 'all'
111
122
 
112
- LogDb.create
113
- ConfDb.create
114
- TagDb.create
115
- WorldDb.create
116
- BeerDb.create
123
+ BeerDb.create_all
117
124
 
118
125
  WorldDb.read_all( opts.world_data_path )
119
126
  BeerDb.read_setup( "setups/#{setup}", opts.data_path )
@@ -311,4 +318,7 @@ on_error do |e|
311
318
  end
312
319
 
313
320
 
314
- exit run(ARGV)
321
+ ### exit run(ARGV) ## note: use Toolii.run( ARGV ) outside of class
322
+
323
+ end # class Toolii
324
+ end # module BeerDb
@@ -1,8 +1,13 @@
1
+ # encoding: utf-8
1
2
 
2
- module BeerDb
3
- MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
- MINOR = 9
5
- PATCH = 13
3
+ # Note: BeerDb::VERSION gets used by core, that is, beerdb-models
4
+
5
+
6
+ module BeerDbCli # todo/check - rename to BeerDbTool or BeerDbCommands or BeerDbShell ??
7
+
8
+ MAJOR = 0
9
+ MINOR = 10
10
+ PATCH = 0
6
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
12
 
8
13
  def self.version
@@ -14,7 +19,8 @@ module BeerDb
14
19
  end
15
20
 
16
21
  def self.root
17
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
22
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
18
23
  end
19
- end # module BeerDb
24
+
25
+ end # module BeerDbCli
20
26
 
@@ -1,15 +1,9 @@
1
+ # encoding: utf-8
2
+
1
3
  ## for use to run with interactive ruby (irb)
2
4
  ## e.g. irb -r sportdb/console
3
5
 
4
- require 'beerdb'
5
-
6
- # some ruby stdlibs
7
-
8
- require 'logger'
9
- require 'pp' # pretty printer
10
- require 'uri'
11
- require 'json'
12
- require 'yaml'
6
+ require 'beerdb/models'
13
7
 
14
8
 
15
9
  ## shortcuts for models
@@ -29,7 +23,7 @@ Prop = WorldDb::Models::Prop
29
23
 
30
24
  DB_CONFIG = {
31
25
  adapter: 'sqlite3',
32
- database: 'beer.db'
26
+ database: './beer.db'
33
27
  }
34
28
 
35
29
  pp DB_CONFIG
data/lib/beerdb.rb CHANGED
@@ -1,123 +1,27 @@
1
- ###
2
- # NB: for local testing run like:
3
- #
4
- # 1.9.x: ruby -Ilib lib/beerdb.rb
1
+ # encoding: utf-8
5
2
 
6
- # core and stlibs
3
+ require 'beerdb/models' # Note: pull in all required deps via beerdb-models
7
4
 
8
- ## stdlibs
9
- # -- get required already by worlddb (remove ??)
10
5
 
11
- require 'yaml'
12
- require 'pp'
13
- require 'logger'
14
- require 'optparse'
15
- require 'fileutils'
16
- require 'erb'
17
- require 'uri'
18
-
19
-
20
- # 3rd party gems / libs
21
-
22
- require 'zip' ## (optionally for textutils e.g. soft dependency - pull in here)
23
-
24
-
25
- # -- get required by worlddb
26
- # require 'active_record' ## todo: add sqlite3? etc.
27
- # require 'logutils'
28
- # require 'textutils'
29
-
30
- require 'worlddb'
6
+ require 'gli'
31
7
 
8
+ require 'datafile'
9
+ require 'fetcher'
32
10
 
33
11
  # our own code
34
12
 
35
- require 'beerdb/version' ## version always goes first
36
-
37
- require 'beerdb/models/forward'
38
- require 'beerdb/models/world/country'
39
- require 'beerdb/models/world/region'
40
- require 'beerdb/models/world/city'
41
- require 'beerdb/models/tag'
42
- require 'beerdb/models/beer'
43
- require 'beerdb/models/brand'
44
- require 'beerdb/models/brewery'
45
-
46
-
47
- require 'beerdb/serializers/beer'
48
- require 'beerdb/serializers/brewery'
49
-
50
- require 'beerdb/schema'
51
- require 'beerdb/reader'
52
- require 'beerdb/reader_file'
53
- require 'beerdb/reader_zip'
54
- require 'beerdb/deleter'
55
- require 'beerdb/stats'
13
+ require 'beerdb/cli/version' ## version always goes first
14
+ require 'beerdb/cli/opts'
15
+ require 'beerdb/cli/main'
56
16
 
57
17
 
58
18
  module BeerDb
59
19
 
60
20
  def self.main
61
- require 'beerdb/cli/main'
62
- # Runner.new.run(ARGV) old code
63
- end
64
-
65
- def self.create
66
- CreateDb.new.up
67
-
68
- ### fix: make optional do NOT auto create here
69
- ### fix: use if defined? BeerDbNote or similar or/and check if table exist ??
70
- ### or move to beerdb-note ??
71
-
72
- # CreateDbExtrasUsers.new.up
73
- # CreateDbExtrasBookmarks.new.up
74
- # CreateDbExtrasDrinks.new.up
75
- # CreateDbExtrasNotes.new.up
76
-
77
- ConfDb::Model::Prop.create!( key: 'db.schema.beer.version', value: VERSION )
78
- end
79
-
80
-
81
- def self.read( ary, include_path )
82
- reader = Reader.new( include_path )
83
- ary.each do |name|
84
- reader.load( name )
85
- end
86
- end
87
-
88
- def self.read_setup( setup, include_path, opts={} )
89
- reader = Reader.new( include_path, opts )
90
- reader.load_setup( setup )
91
- end
92
-
93
- def self.read_setup_from_zip( zip_name, setup, include_path, opts={} ) ## todo/check - use a better (shorter) name ??
94
- reader = ZipReader.new( zip_name, include_path, opts )
95
- reader.load_setup( setup )
96
- reader.close
21
+ exit Tool.new.run(ARGV)
97
22
  end
98
23
 
99
- def self.read_all( include_path, opts={} ) # load all builtins (using plain text reader); helper for convenience
100
- read_setup( 'setups/all', include_path, opts )
101
- end # method read_all
102
-
103
-
104
- # delete ALL records (use with care!)
105
- def self.delete!
106
- puts '*** deleting beer table records/data...'
107
- Deleter.new.run
108
- end # method delete!
109
-
110
- def self.tables
111
- Stats.new.tables
112
- end
113
-
114
-
115
24
  end # module BeerDb
116
25
 
117
26
 
118
- if __FILE__ == $0
119
- BeerDb.main
120
- else
121
- # say hello
122
- puts BeerDb.banner
123
- end
27
+ BeerDb.main if __FILE__ == $0