beerdb-models 1.1.0 → 1.1.1

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: 4e0814546ffaf1bdce1f0a10a33183cb5d3642c4
4
- data.tar.gz: 95860781d2554c27001e6db34eb1b926bba44473
3
+ metadata.gz: 7a3214a36bec05faea115c2cb1bcb5dd3dff5526
4
+ data.tar.gz: c98220129e209b2f6c7d2a89227eb2d721771200
5
5
  SHA512:
6
- metadata.gz: b0190214a599104891fe8620f3fd04b33001cbcc4c4651a93e8111ac6aacf782f471f336a50bd56a82aa1a87bd68c260d8c3005e0f4122c996c15651542282bb
7
- data.tar.gz: 7f26566ee130d0a570f8bdd5abe363ebd496ef6ff11bbe8878a6704564a08c3c5ddc72b0aedefcdd125c4146cc57e2bb73cc3c0b2b0eaa0af3fb77ac5d77b4a7
6
+ metadata.gz: c5319080d890054876e3cbae262b1e869a2c2aa24d1c29e76dab2337652f71333f9b9a24ebda39ef2eecf9f15e56a96d3ad0d4f4008a39289d44b3412cbe1b4b
7
+ data.tar.gz: 65fe65c742cf7aa322962e4f7197408f35fda43d6851a01630155c0ac60a90536dc178815f34e74c5ea01f29945806622c24b8c84b6084b79573f39c9153ffd3
data/lib/beerdb/models.rb CHANGED
@@ -99,6 +99,73 @@ module BeerDb
99
99
  end
100
100
 
101
101
 
102
+ def self.connect( config={} )
103
+
104
+ if config.empty?
105
+ puts "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
106
+
107
+ db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///beer.db' )
108
+
109
+ if db.scheme == 'postgres'
110
+ config = {
111
+ adapter: 'postgresql',
112
+ host: db.host,
113
+ port: db.port,
114
+ username: db.user,
115
+ password: db.password,
116
+ database: db.path[1..-1],
117
+ encoding: 'utf8'
118
+ }
119
+ else # assume sqlite3
120
+ config = {
121
+ adapter: db.scheme, # sqlite3
122
+ database: db.path[1..-1] # beer.db (Note: cut off leading /, thus 1..-1)
123
+ }
124
+ end
125
+ end
126
+
127
+ puts "Connecting to db using settings: "
128
+ pp config
129
+ ActiveRecord::Base.establish_connection( config )
130
+ # ActiveRecord::Base.logger = Logger.new( STDOUT )
131
+
132
+
133
+ ## if sqlite3 add (use) some pragmas for speedups
134
+ if config[:adapter] == 'sqlite3'
135
+ if config[:database] == ':memory:'
136
+ ## do nothing for in memory database; no pragmas needed
137
+ puts "sqlite3 - no pragmas; using in memory database"
138
+ else
139
+ puts "sqlite3 - pragmas for speedup"
140
+ con = ActiveRecord::Base.connection
141
+ con.execute( 'PRAGMA synchronous=OFF;' )
142
+ con.execute( 'PRAGMA journal_mode=OFF;' )
143
+ con.execute( 'PRAGMA temp_store=MEMORY;' )
144
+ end
145
+ end
146
+ end # method connect
147
+
148
+
149
+ def self.setup_in_memory_db
150
+ # Database Setup & Config
151
+
152
+ config = {
153
+ adapter: 'sqlite3',
154
+ database: ':memory:'
155
+ }
156
+
157
+ pp config
158
+
159
+ ActiveRecord::Base.logger = Logger.new( STDOUT )
160
+ ## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
161
+
162
+ ## Note: every connect will create a new empty in memory db
163
+ ActiveRecord::Base.establish_connection( config )
164
+
165
+ ## build schema
166
+ BeerDb.create_all
167
+ end
168
+
102
169
  end # module BeerDb
103
170
 
104
171
 
@@ -3,7 +3,7 @@
3
3
  module BeerDb
4
4
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
5
5
  MINOR = 1
6
- PATCH = 0
6
+ PATCH = 1
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
data/test/helper.rb CHANGED
@@ -20,44 +20,11 @@ Brand = BeerDb::Model::Brand
20
20
  Brewery = BeerDb::Model::Brewery
21
21
 
22
22
 
23
- def setup_in_memory_db
24
- # Database Setup & Config
23
+ BeerDb.setup_in_memory_db()
25
24
 
26
- db_config = {
27
- adapter: 'sqlite3',
28
- database: ':memory:'
29
- }
25
+ ## add some counties
26
+ AT = Country.create!( key: 'at', title: 'Austria', code: 'AUT', pop: 0, area: 0 )
27
+ W = State.create!( key: 'w', title: 'Wien', country_id: AT.id )
30
28
 
31
- pp db_config
32
-
33
- ActiveRecord::Base.logger = Logger.new( STDOUT )
34
- ## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
35
-
36
- ## NB: every connect will create a new empty in memory db
37
- ActiveRecord::Base.establish_connection( db_config )
38
-
39
-
40
- ## build schema
41
- BeerDb.create_all
42
- end
43
-
44
-
45
- def fillup_in_memory_db
46
- ## add some counties
47
-
48
- at = Country.create!( key: 'at', title: 'Austria', code: 'AUT', pop: 0, area: 0 )
49
- State.create!( key: 'w', title: 'Wien', country_id: at.id )
50
-
51
- de = Country.create!( key: 'de', title: 'Germany', code: 'DEU', pop: 0, area: 0 )
52
- State.create!( key: 'by', title: 'Bayern', country_id: de.id )
53
-
54
- end
55
-
56
- setup_in_memory_db()
57
- fillup_in_memory_db()
58
-
59
- AT = Country.find_by!( key: 'at' )
60
- W = State.find_by!( key: 'w' )
61
-
62
- DE = Country.find_by!( key: 'de' )
63
- BY = State.find_by!( key: 'by' )
29
+ DE = Country.create!( key: 'de', title: 'Germany', code: 'DEU', pop: 0, area: 0 )
30
+ BY = State.create!( key: 'by', title: 'Bayern', country_id: DE.id )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beerdb-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer