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 +4 -4
- data/lib/poefy/pg.rb +17 -18
- data/lib/poefy/pg/version.rb +2 -2
- data/poefy-pg.gemspec +1 -1
- data/spec/poefy_pg_spec.rb +54 -39
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c046258dedd30f3dfa12687e8a51dcb0109b321
|
4
|
+
data.tar.gz: 23b5c577a8daab3e38b9641147926fbdb7a072a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
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
|
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 ||=
|
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
|
-
|
229
|
-
|
230
|
-
|
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.
|
data/lib/poefy/pg/version.rb
CHANGED
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.
|
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
|
data/spec/poefy_pg_spec.rb
CHANGED
@@ -119,26 +119,31 @@ describe Poefy::Poem, "-- Postgres" do
|
|
119
119
|
|
120
120
|
describe ":rhyme option" do
|
121
121
|
|
122
|
-
describe "should
|
122
|
+
describe "should raise Poefy::MissingFormOrRhyme" do
|
123
123
|
it "blank, no argument" do
|
124
|
-
|
125
|
-
|
124
|
+
expect {
|
125
|
+
@poefy.poem
|
126
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
126
127
|
end
|
127
128
|
it "({ })" do
|
128
|
-
|
129
|
-
|
129
|
+
expect {
|
130
|
+
@poefy.poem ({ })
|
131
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
130
132
|
end
|
131
133
|
it "({ rhyme: nil })" do
|
132
|
-
|
133
|
-
|
134
|
+
expect {
|
135
|
+
@poefy.poem ({ rhyme: nil })
|
136
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
134
137
|
end
|
135
138
|
it "({ rhyme: ' ' })" do
|
136
|
-
|
137
|
-
|
139
|
+
expect {
|
140
|
+
@poefy.poem ({ rhyme: ' ' })
|
141
|
+
}.to raise_error(Poefy::MissingFormOrRhyme)
|
138
142
|
end
|
139
143
|
it "({ rhyme: '' })" do
|
140
|
-
|
141
|
-
|
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
|
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
|
-
|
174
|
-
|
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
|
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
|
-
|
184
|
-
|
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
|
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
|
-
|
209
|
-
|
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
|
232
|
+
describe "should raise error if given a named form it can't fulfil" do
|
225
233
|
it "({ form: 'sonnet' })" do
|
226
|
-
|
227
|
-
|
234
|
+
expect {
|
235
|
+
@poefy.poem ({ form: 'sonnet' })
|
236
|
+
}.to raise_error(Poefy::NotEnoughData)
|
228
237
|
end
|
229
238
|
it "({ form: :villanelle })" do
|
230
|
-
|
231
|
-
|
239
|
+
expect {
|
240
|
+
@poefy.poem ({ form: 'villanelle' })
|
241
|
+
}.to raise_error(Poefy::NotEnoughData)
|
232
242
|
end
|
233
243
|
end
|
234
244
|
|
235
|
-
describe "should
|
245
|
+
describe "should raise error if given a junk named form" do
|
236
246
|
it "({ form: 'sonnet_junk' })" do
|
237
|
-
|
238
|
-
|
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
|
-
|
242
|
-
|
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
|
-
|
246
|
-
|
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
|
322
|
+
describe "should raise Poefy::NotEnoughData" do
|
310
323
|
it "({ form: :sonnet, acrostic: 'qqqqqqqqqqqqqq' })" do
|
311
|
-
|
312
|
-
|
313
|
-
|
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
|
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
|
-
|
342
|
-
|
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:
|
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-
|
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.
|
75
|
+
version: '1.1'
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: 1.
|
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.
|
85
|
+
version: '1.1'
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.
|
88
|
+
version: 1.1.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: pg
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|