poefy-pg 0.1.0 → 1.1.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: 562ca9a5d0e1e8fc84fce3f1d2cc1191f67b72b8
4
- data.tar.gz: 532339860c2f1ad84288c8232162b31de8854154
3
+ metadata.gz: 2c046258dedd30f3dfa12687e8a51dcb0109b321
4
+ data.tar.gz: 23b5c577a8daab3e38b9641147926fbdb7a072a4
5
5
  SHA512:
6
- metadata.gz: 8a95524ade873f8ff08785a8d4abdb94bb808f15c92fb73bf5fb6daa11f6c9f62f288ef86d44fc305f186a31eb6ea2369927f9471a769b00bb88c6a713cfa270
7
- data.tar.gz: 1f7f41a631894cb7191805f0d8024290dc2757c0f1fdcd2c10ba4d3c6a69dbf4f5341407d5174262ce1f8ec00c0ef146339dea24cf540d688d713b35580863b6
6
+ metadata.gz: 63057472cba2d216ae52ff984595fd850ff0eb41f45e454301f0ca8c9cfe8fa9e937ad7a31c6cbd5bbb7d2351ae136cdefb2d191c46e6c900968936c61b849dc
7
+ data.tar.gz: f48350f446d19cb4ba49d13124038e9312be7c00e0d91f6105a84fb985e3d85f77e81ded0d76ccd74ac669dd996f9ded59ab48f561cf1b6bcdbece1c5a5c8501
data/lib/poefy/pg.rb CHANGED
@@ -15,22 +15,25 @@ module Poefy
15
15
 
16
16
  class Database
17
17
 
18
- # Open a connection, execute a query, close the connection.
18
+ # Details for the database connection.
19
+ def self.connection
20
+ PG.connect(
21
+ :dbname => 'poefy',
22
+ :user => 'poefy',
23
+ :password => 'poefy'
24
+ )
25
+ end
26
+
27
+ # Open a class-wide connection, execute a query.
19
28
  def self.single_exec! sql, sql_args = nil
20
29
  output = nil
21
30
  begin
22
- con = PG.connect(
23
- :dbname => 'poefy',
24
- :user => 'poefy',
25
- :password => 'poefy'
26
- )
31
+ @@con ||= Database::connection
27
32
  output = if sql_args
28
- con.exec(sql, [*sql_args]).values
33
+ @@con.exec(sql, [*sql_args]).values
29
34
  else
30
- con.exec(sql).values
35
+ @@con.exec(sql).values
31
36
  end
32
- ensure
33
- con.close if con
34
37
  end
35
38
  output
36
39
  end
@@ -137,11 +140,7 @@ module Poefy
137
140
 
138
141
  # Open a connection to the database.
139
142
  def open_connection
140
- @db ||= PG.connect(
141
- :dbname => 'poefy',
142
- :user => 'poefy',
143
- :password => 'poefy'
144
- )
143
+ @db ||= Database::connection
145
144
  end
146
145
 
147
146
  # Execute a query.
@@ -225,9 +224,9 @@ module Poefy
225
224
  db.prepare key.to_s, value
226
225
  end
227
226
  rescue
228
- handle_error \
229
- "ERROR: Database table structure is invalid.\n" +
230
- " Please manually DROP the corrupt table and recreate it."
227
+ msg = "ERROR: Database table structure is invalid." +
228
+ "\n Please manually DROP the corrupt table and recreate it."
229
+ raise Poefy::StructureInvalid.new(msg)
231
230
  end
232
231
 
233
232
  # Find rhymes and counts greater than a certain length.
@@ -6,7 +6,7 @@ module Poefy
6
6
  module Pg
7
7
 
8
8
  def self.version_number
9
- major = 0
9
+ major = 1
10
10
  minor = 1
11
11
  tiny = 0
12
12
  pre = nil
@@ -16,7 +16,7 @@ module Poefy
16
16
  end
17
17
 
18
18
  def self.version_date
19
- '2017-10-02'
19
+ '2017-10-31'
20
20
  end
21
21
 
22
22
  end
data/poefy-pg.gemspec CHANGED
@@ -26,6 +26,6 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency('rspec', '~> 3.0')
27
27
  s.add_development_dependency('ruby_rhymes', '~> 0.1')
28
28
 
29
- s.add_runtime_dependency('poefy', '~> 1.0', '>= 1.0.0')
29
+ s.add_runtime_dependency('poefy', '~> 1.1', '>= 1.1.0')
30
30
  s.add_runtime_dependency('pg', '~> 0.21', '>= 0.21.0')
31
31
  end
@@ -119,26 +119,31 @@ describe Poefy::Poem, "-- Postgres" do
119
119
 
120
120
  describe ":rhyme option" do
121
121
 
122
- describe "should return nil" do
122
+ describe "should raise Poefy::MissingFormOrRhyme" do
123
123
  it "blank, no argument" do
124
- poem = @poefy.poem
125
- expect(poem).to be_nil
124
+ expect {
125
+ @poefy.poem
126
+ }.to raise_error(Poefy::MissingFormOrRhyme)
126
127
  end
127
128
  it "({ })" do
128
- poem = @poefy.poem ({ })
129
- expect(poem).to be_nil
129
+ expect {
130
+ @poefy.poem ({ })
131
+ }.to raise_error(Poefy::MissingFormOrRhyme)
130
132
  end
131
133
  it "({ rhyme: nil })" do
132
- poem = @poefy.poem ({ rhyme: nil })
133
- expect(poem).to be_nil
134
+ expect {
135
+ @poefy.poem ({ rhyme: nil })
136
+ }.to raise_error(Poefy::MissingFormOrRhyme)
134
137
  end
135
138
  it "({ rhyme: ' ' })" do
136
- poem = @poefy.poem ({ rhyme: ' ' })
137
- expect(poem).to be_nil
139
+ expect {
140
+ @poefy.poem ({ rhyme: ' ' })
141
+ }.to raise_error(Poefy::MissingFormOrRhyme)
138
142
  end
139
143
  it "({ rhyme: '' })" do
140
- poem = @poefy.poem ({ rhyme: '' })
141
- expect(poem).to be_nil
144
+ expect {
145
+ @poefy.poem ({ rhyme: '' })
146
+ }.to raise_error(Poefy::MissingFormOrRhyme)
142
147
  end
143
148
  end
144
149
 
@@ -165,23 +170,25 @@ describe Poefy::Poem, "-- Postgres" do
165
170
  end
166
171
  end
167
172
 
168
- describe "should be nil if can't parse rhyme string" do
173
+ describe "should raise error if can't parse rhyme string" do
169
174
  rhymes = %w{a1 b1 ab1 Ab1 AAAAABb1 1 1111 1122 11221 ;;::1. }
170
175
  rhymes += ['AA Bb1','11 11','11 1 1','..1.']
171
176
  rhymes.each do |i|
172
177
  it "({ rhyme: '#{i}' })" do
173
- poem = @poefy.poem ({ rhyme: i })
174
- expect(poem).to be_nil
178
+ expect {
179
+ @poefy.poem ({ rhyme: i })
180
+ }.to raise_error(Poefy::RhymeError)
175
181
  end
176
182
  end
177
183
  end
178
184
 
179
- describe "should be nil if can't complete rhyme string" do
185
+ describe "should raise error if can't complete rhyme string" do
180
186
  rhymes = %w{aaaaaa abcd aaaaabbbbb}
181
187
  rhymes.each do |i|
182
188
  it "({ rhyme: '#{i}' })" do
183
- poem = @poefy.poem ({ rhyme: i })
184
- expect(poem).to be_nil
189
+ expect {
190
+ @poefy.poem ({ rhyme: i })
191
+ }.to raise_error(Poefy::NotEnoughData)
185
192
  end
186
193
  end
187
194
  end
@@ -201,12 +208,13 @@ describe Poefy::Poem, "-- Postgres" do
201
208
  end
202
209
  end
203
210
 
204
- describe "should be nil if can't complete repeating rhyme string" do
211
+ describe "should raise error if can't complete repeating rhyme string" do
205
212
  lines = 200
206
213
  it "({ rhyme: ('A'..'D').to_a.map { |i| i * #{lines} }.join })" do
207
214
  rhyme = ('A'..'D').to_a.map { |i| i * lines }.join
208
- poem = @poefy.poem ({ rhyme: rhyme })
209
- expect(poem).to be_nil
215
+ expect {
216
+ @poefy.poem ({ rhyme: rhyme })
217
+ }.to raise_error(Poefy::NotEnoughData)
210
218
  end
211
219
  end
212
220
 
@@ -221,29 +229,34 @@ describe Poefy::Poem, "-- Postgres" do
221
229
  end
222
230
  end
223
231
 
224
- describe "should be nil if given a named form it can't fulfil" do
232
+ describe "should raise error if given a named form it can't fulfil" do
225
233
  it "({ form: 'sonnet' })" do
226
- poem = @poefy.poem ({ form: 'sonnet' })
227
- expect(poem).to be_nil
234
+ expect {
235
+ @poefy.poem ({ form: 'sonnet' })
236
+ }.to raise_error(Poefy::NotEnoughData)
228
237
  end
229
238
  it "({ form: :villanelle })" do
230
- poem = @poefy.poem ({ form: :villanelle })
231
- expect(poem).to be_nil
239
+ expect {
240
+ @poefy.poem ({ form: 'villanelle' })
241
+ }.to raise_error(Poefy::NotEnoughData)
232
242
  end
233
243
  end
234
244
 
235
- describe "should be nil if given a junk named form" do
245
+ describe "should raise error if given a junk named form" do
236
246
  it "({ form: 'sonnet_junk' })" do
237
- poem = @poefy.poem ({ form: 'sonnet_junk' })
238
- expect(poem).to be_nil
247
+ expect {
248
+ @poefy.poem ({ form: 'sonnet_junk' })
249
+ }.to raise_error(Poefy::MissingFormOrRhyme)
239
250
  end
240
251
  it "({ form: :not_a_form })" do
241
- poem = @poefy.poem ({ form: :not_a_form })
242
- expect(poem).to be_nil
252
+ expect {
253
+ @poefy.poem ({ form: :not_a_form })
254
+ }.to raise_error(Poefy::MissingFormOrRhyme)
243
255
  end
244
256
  it "({ form: :not_a_form, indent: '0010' })" do
245
- poem = @poefy.poem ({ form: :not_a_form, indent: '0010' })
246
- expect(poem).to be_nil
257
+ expect {
258
+ @poefy.poem ({ form: :not_a_form, indent: '0010' })
259
+ }.to raise_error(Poefy::MissingFormOrRhyme)
247
260
  end
248
261
  end
249
262
 
@@ -306,11 +319,12 @@ describe Poefy::Poem, "-- Postgres" do
306
319
  expect(poem.count).to be 14
307
320
  end
308
321
  end
309
- describe "should fail to be created" do
322
+ describe "should raise Poefy::NotEnoughData" do
310
323
  it "({ form: :sonnet, acrostic: 'qqqqqqqqqqqqqq' })" do
311
- poem = @poefy.poem ({ form: :sonnet,
312
- acrostic: 'qqqqqqqqqqqqqq' })
313
- expect(poem).to be_nil
324
+ expect {
325
+ @poefy.poem ({ form: :sonnet,
326
+ acrostic: 'qqqqqqqqqqqqqq' })
327
+ }.to raise_error(Poefy::NotEnoughData)
314
328
  end
315
329
  end
316
330
  end
@@ -334,12 +348,13 @@ describe Poefy::Poem, "-- Postgres" do
334
348
  end
335
349
  end
336
350
 
337
- describe "should fail to be created" do
351
+ describe "should raise Poefy::NotEnoughData" do
338
352
  forms_fail.each do |form|
339
353
  it "({ form: #{form} })" do
340
354
  4.times do
341
- poem = @poefy.poem ({ form: form })
342
- expect(poem).to be_nil
355
+ expect {
356
+ @poefy.poem ({ form: form })
357
+ }.to raise_error(Poefy::NotEnoughData)
343
358
  end
344
359
  end
345
360
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poefy-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,20 +72,20 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.0'
75
+ version: '1.1'
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 1.0.0
78
+ version: 1.1.0
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - "~>"
84
84
  - !ruby/object:Gem::Version
85
- version: '1.0'
85
+ version: '1.1'
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 1.0.0
88
+ version: 1.1.0
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pg
91
91
  requirement: !ruby/object:Gem::Requirement