pliny 0.27.1 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny/commands/updater.rb +5 -5
- data/lib/pliny/log.rb +7 -5
- data/lib/pliny/tasks/db.rake +10 -13
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +1 -1
- data/spec/commands/creator_spec.rb +17 -15
- data/spec/commands/updater_spec.rb +11 -9
- data/spec/db_support_spec.rb +13 -10
- data/spec/integration_spec.rb +14 -9
- data/spec/log_spec.rb +62 -1
- metadata +13 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fdeb50812c8474db1b462be06a13943d901cc06c51044c39fffe9533c2d67d4
|
4
|
+
data.tar.gz: b70639846466fc0efa37a62fc55551ec4386ccfd0ac3141e041bef88744f4610
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9e248f7961808f6d862d6b77c8065afc7716cf7861ecb0c508d470819ba012a0a0cd2454352b4854bbaad4cb23f18166ace07cca14035eb514ec71fdf908a96
|
7
|
+
data.tar.gz: 7b7120d718e286d1ecb7cead9ed19db8a823b4aefe66f1601d824cfc172b46c89c2cbbe2ebdccfaf0e113b8afb862bd2c85d76bf55438ca1dbd5ea89bfc3f28d
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "fileutils"
|
2
|
+
require "pathname"
|
3
|
+
require "pliny/version"
|
4
|
+
require "uri"
|
5
5
|
|
6
6
|
module Pliny::Commands
|
7
7
|
class Updater
|
@@ -37,7 +37,7 @@ module Pliny::Commands
|
|
37
37
|
|
38
38
|
# we need a local copy of the pliny repo to produce a diff
|
39
39
|
def ensure_repo_available
|
40
|
-
if File.
|
40
|
+
if File.exist?(repo_dir)
|
41
41
|
unless system("cd #{repo_dir} && git fetch --tags")
|
42
42
|
abort("Could not update Pliny repo at #{repo_dir}")
|
43
43
|
end
|
data/lib/pliny/log.rb
CHANGED
@@ -124,7 +124,6 @@ module Pliny
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def quote_string(k, v)
|
127
|
-
# try to find a quote style that fits
|
128
127
|
if !v.include?('"')
|
129
128
|
%{#{k}="#{v}"}
|
130
129
|
elsif !v.include?("'")
|
@@ -140,19 +139,22 @@ module Pliny
|
|
140
139
|
|
141
140
|
def unparse_pair(k, v)
|
142
141
|
v = v.call if v.is_a?(Proc)
|
143
|
-
|
142
|
+
|
144
143
|
if v == nil
|
145
144
|
nil
|
146
145
|
elsif v == true
|
147
146
|
k
|
148
147
|
elsif v.is_a?(Float)
|
149
148
|
"#{k}=#{format("%.3f", v)}"
|
150
|
-
elsif v.is_a?(String) && v =~ /\s/
|
151
|
-
quote_string(k, v)
|
152
149
|
elsif v.is_a?(Time)
|
153
150
|
"#{k}=#{v.iso8601}"
|
154
151
|
else
|
155
|
-
"#{
|
152
|
+
v = "#{v}"
|
153
|
+
if v =~ /\s/
|
154
|
+
quote_string(k, v)
|
155
|
+
else
|
156
|
+
"#{k}=#{v}"
|
157
|
+
end
|
156
158
|
end
|
157
159
|
end
|
158
160
|
end
|
data/lib/pliny/tasks/db.rake
CHANGED
@@ -32,12 +32,12 @@ begin
|
|
32
32
|
|
33
33
|
desc "Seed the database with data"
|
34
34
|
task :seed do
|
35
|
-
if File.exist?(
|
35
|
+
if File.exist?("./db/seeds.rb")
|
36
36
|
database_urls.each do |database_url|
|
37
37
|
# make a DB instance available to the seeds file
|
38
|
-
self.class.send(:remove_const,
|
39
|
-
self.class.const_set(
|
40
|
-
load
|
38
|
+
self.class.send(:remove_const, "DB") if self.class.const_defined?("DB")
|
39
|
+
self.class.const_set("DB", Sequel.connect(database_url))
|
40
|
+
load "db/seeds.rb"
|
41
41
|
end
|
42
42
|
disconnect
|
43
43
|
end
|
@@ -66,7 +66,7 @@ begin
|
|
66
66
|
admin_url = Pliny::DbSupport.admin_url(database_url)
|
67
67
|
db = Sequel.connect(admin_url)
|
68
68
|
name = name_from_uri(database_url)
|
69
|
-
db.run(%
|
69
|
+
db.run(%(DROP DATABASE IF EXISTS "#{name}"))
|
70
70
|
puts "Dropped `#{name}`"
|
71
71
|
end
|
72
72
|
disconnect
|
@@ -75,7 +75,7 @@ begin
|
|
75
75
|
namespace :schema do
|
76
76
|
desc "Load the database schema"
|
77
77
|
task :load do
|
78
|
-
if File.
|
78
|
+
if File.exist?("./db/schema.sql")
|
79
79
|
schema = File.read("./db/schema.sql")
|
80
80
|
database_urls.each do |database_url|
|
81
81
|
db = Sequel.connect(database_url)
|
@@ -118,14 +118,14 @@ begin
|
|
118
118
|
end
|
119
119
|
|
120
120
|
desc "Merges migrations into schema and removes them"
|
121
|
-
task :
|
121
|
+
task merge: ["db:setup", "db:schema:dump"] do
|
122
122
|
FileUtils.rm Dir["./db/migrate/*.rb"]
|
123
123
|
puts "Removed migrations"
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
desc "Setup the database"
|
128
|
-
task :
|
128
|
+
task setup: [:drop, :create, "schema:load", :migrate, :seed]
|
129
129
|
|
130
130
|
private
|
131
131
|
|
@@ -138,12 +138,10 @@ begin
|
|
138
138
|
if ENV["DATABASE_URL"]
|
139
139
|
[ENV["DATABASE_URL"]]
|
140
140
|
else
|
141
|
-
%w
|
141
|
+
%w[.env .env.test].map { |env_file|
|
142
142
|
env_path = "./#{env_file}"
|
143
|
-
if File.
|
143
|
+
if File.exist?(env_path)
|
144
144
|
Pliny::Utils.parse_env(env_path)["DATABASE_URL"]
|
145
|
-
else
|
146
|
-
nil
|
147
145
|
end
|
148
146
|
}.compact
|
149
147
|
end
|
@@ -153,7 +151,6 @@ begin
|
|
153
151
|
URI.parse(uri).path[1..-1]
|
154
152
|
end
|
155
153
|
end
|
156
|
-
|
157
154
|
rescue LoadError
|
158
155
|
puts "Couldn't load sequel. Skipping database tasks"
|
159
156
|
end
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "pliny/commands/creator"
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe Pliny::Commands::Creator do
|
5
5
|
before do
|
@@ -7,21 +7,23 @@ describe Pliny::Commands::Creator do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#run!" do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
around do |example|
|
11
|
+
Dir.mktmpdir("plinytest-") do |dir|
|
12
|
+
Dir.chdir(dir) do
|
13
|
+
example.run
|
14
|
+
end
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
it "copies the template app over" do
|
17
19
|
@gen.run!
|
18
|
-
assert File.
|
19
|
-
assert File.
|
20
|
+
assert File.exist?("./foobar")
|
21
|
+
assert File.exist?("./foobar/Gemfile")
|
20
22
|
end
|
21
23
|
|
22
24
|
it "deletes the .git from it" do
|
23
25
|
@gen.run!
|
24
|
-
refute File.
|
26
|
+
refute File.exist?("./foobar/.git")
|
25
27
|
end
|
26
28
|
|
27
29
|
it "deletes the .erb files from it" do
|
@@ -31,25 +33,25 @@ describe Pliny::Commands::Creator do
|
|
31
33
|
|
32
34
|
it "changes DATABASE_URL in .env.sample to use the app name" do
|
33
35
|
@gen.run!
|
34
|
-
db_url = File.read("./foobar/.env.sample").split("\n").detect
|
36
|
+
db_url = File.read("./foobar/.env.sample").split("\n").detect { |line|
|
35
37
|
line.include?("DATABASE_URL=")
|
36
|
-
|
38
|
+
}
|
37
39
|
assert_equal "DATABASE_URL=postgres:///foobar-development", db_url
|
38
40
|
end
|
39
41
|
|
40
42
|
it "changes DATABASE_URL in .env.test to use the app name" do
|
41
43
|
@gen.run!
|
42
|
-
db_url = File.read("./foobar/.env.test").split("\n").detect
|
44
|
+
db_url = File.read("./foobar/.env.test").split("\n").detect { |line|
|
43
45
|
line.include?("DATABASE_URL=")
|
44
|
-
|
46
|
+
}
|
45
47
|
assert_equal "DATABASE_URL=postgres:///foobar-test", db_url
|
46
48
|
end
|
47
49
|
|
48
50
|
it "changes APP_NAME in app.json to use the app name" do
|
49
51
|
@gen.run!
|
50
|
-
db_url = File.read("./foobar/app.json").split("\n").detect
|
52
|
+
db_url = File.read("./foobar/app.json").split("\n").detect { |line|
|
51
53
|
line.include?("\"name\":")
|
52
|
-
|
54
|
+
}
|
53
55
|
assert_equal " \"name\": \"foobar\",", db_url
|
54
56
|
end
|
55
57
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "pliny/commands/updater"
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe Pliny::Commands::Updater do
|
5
5
|
before do
|
@@ -10,19 +10,21 @@ describe Pliny::Commands::Updater do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#run!" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
around do |example|
|
14
|
+
Dir.mktmpdir("plinytest-") do |dir|
|
15
|
+
Dir.chdir(dir) do
|
16
|
+
File.open("./Gemfile.lock", "w") do |f|
|
17
|
+
f.puts " pliny (0.6.3)"
|
18
|
+
end
|
19
|
+
example.run
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
it "creates a patch with Pliny diffs between the two versions" do
|
23
25
|
@cmd.run!
|
24
26
|
patch = File.read(@cmd.patch_file)
|
25
|
-
assert patch.include?(
|
27
|
+
assert patch.include?("--- a/Gemfile")
|
26
28
|
assert patch.include?('-gem "pliny", "~> 0.6"')
|
27
29
|
end
|
28
30
|
end
|
data/spec/db_support_spec.rb
CHANGED
@@ -6,15 +6,18 @@ describe Pliny::DbSupport do
|
|
6
6
|
let(:logger) { Logger.new(StringIO.new) }
|
7
7
|
let(:support) { Pliny::DbSupport.new(url, logger) }
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
around do |example|
|
10
|
+
Dir.mktmpdir("plinytest-") do |dir|
|
11
|
+
Dir.chdir(dir) do
|
12
|
+
FileUtils.mkdir_p("./db/migrate")
|
13
|
+
|
14
|
+
example.run
|
15
|
+
end
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
|
-
before
|
19
|
+
before do
|
14
20
|
DB.tables.each { |t| DB.drop_table(t) }
|
15
|
-
FileUtils.rm_rf(@path)
|
16
|
-
FileUtils.mkdir_p("#{@path}/db/migrate")
|
17
|
-
Dir.chdir(@path)
|
18
21
|
end
|
19
22
|
|
20
23
|
describe ".admin_url" do
|
@@ -33,7 +36,7 @@ describe Pliny::DbSupport do
|
|
33
36
|
|
34
37
|
describe "#migrate" do
|
35
38
|
before do
|
36
|
-
File.open("
|
39
|
+
File.open("./db/migrate/#{Time.now.to_i}_create_foo.rb", "w") do |f|
|
37
40
|
f.puts "
|
38
41
|
Sequel.migration do
|
39
42
|
change do
|
@@ -57,11 +60,11 @@ describe Pliny::DbSupport do
|
|
57
60
|
describe "#rollback" do
|
58
61
|
before do
|
59
62
|
@t = Time.now
|
60
|
-
File.open("
|
63
|
+
File.open("./db/migrate/#{(@t - 2).to_i}_first.rb", "w") do |f|
|
61
64
|
f.puts "Sequel.migration { change { create_table(:first) } }"
|
62
65
|
end
|
63
66
|
|
64
|
-
File.open("
|
67
|
+
File.open("./db/migrate/#{(@t - 1).to_i}_second.rb", "w") do |f|
|
65
68
|
f.puts "Sequel.migration { change { create_table(:second) } }"
|
66
69
|
end
|
67
70
|
end
|
@@ -80,7 +83,7 @@ describe Pliny::DbSupport do
|
|
80
83
|
end
|
81
84
|
|
82
85
|
it "handles databases not migrated (schema_migrations is empty)" do
|
83
|
-
support.migrate
|
86
|
+
support.migrate((@t - 2).to_i)
|
84
87
|
support.rollback # destroy table, leave schema_migrations
|
85
88
|
support.rollback # should noop
|
86
89
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -2,19 +2,24 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe "Pliny integration test" do
|
4
4
|
before(:all) do
|
5
|
-
|
6
|
-
|
7
|
-
Dir.
|
5
|
+
@original_dir = Dir.pwd
|
6
|
+
|
7
|
+
test_dir = Dir.mktmpdir("plinytest-")
|
8
|
+
Dir.chdir(test_dir)
|
8
9
|
|
9
10
|
bash "pliny-new myapp"
|
10
11
|
|
11
|
-
Dir.chdir("
|
12
|
+
Dir.chdir("myapp")
|
12
13
|
bash "bin/setup"
|
13
14
|
end
|
14
15
|
|
16
|
+
after(:all) do
|
17
|
+
Dir.chdir(@original_dir)
|
18
|
+
end
|
19
|
+
|
15
20
|
describe "bin/setup" do
|
16
21
|
it "generates .env" do
|
17
|
-
assert File.
|
22
|
+
assert File.exist?("./.env")
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
@@ -24,19 +29,19 @@ describe "Pliny integration test" do
|
|
24
29
|
end
|
25
30
|
|
26
31
|
it "creates the model file" do
|
27
|
-
assert File.
|
32
|
+
assert File.exist?("./lib/models/artist.rb")
|
28
33
|
end
|
29
34
|
|
30
35
|
it "creates the endpoint file" do
|
31
|
-
assert File.
|
36
|
+
assert File.exist?("./lib/endpoints/artists.rb")
|
32
37
|
end
|
33
38
|
|
34
39
|
it "creates the serializer file" do
|
35
|
-
assert File.
|
40
|
+
assert File.exist?("./lib/serializers/artist.rb")
|
36
41
|
end
|
37
42
|
|
38
43
|
it "creates the schema file" do
|
39
|
-
assert File.
|
44
|
+
assert File.exist?("./schema/schemata/artist.yaml")
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
data/spec/log_spec.rb
CHANGED
@@ -5,7 +5,6 @@ describe Pliny::Log do
|
|
5
5
|
@io = StringIO.new
|
6
6
|
Pliny.stdout = @io
|
7
7
|
Pliny.stderr = @io
|
8
|
-
allow(@io).to receive(:print)
|
9
8
|
end
|
10
9
|
|
11
10
|
after do
|
@@ -130,4 +129,66 @@ describe Pliny::Log do
|
|
130
129
|
end
|
131
130
|
end
|
132
131
|
end
|
132
|
+
|
133
|
+
describe "unparsing" do
|
134
|
+
it "removes nils from log" do
|
135
|
+
expect(@io).to receive(:print).with("\n")
|
136
|
+
|
137
|
+
Pliny.log(foo: nil)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "leaves bare keys for true values" do
|
141
|
+
expect(@io).to receive(:print).with("foo\n")
|
142
|
+
|
143
|
+
Pliny.log(foo: true)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "truncates floats" do
|
147
|
+
expect(@io).to receive(:print).with("foo=3.142\n")
|
148
|
+
|
149
|
+
Pliny.log(foo: Math::PI)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "outputs times in ISO8601 format" do
|
153
|
+
expect(@io).to receive(:print).with("foo=2020-01-01T00:00:00Z\n")
|
154
|
+
|
155
|
+
Pliny.log(foo: Time.utc(2020))
|
156
|
+
end
|
157
|
+
|
158
|
+
it "quotes strings that contain spaces" do
|
159
|
+
expect(@io).to receive(:print).with("foo=\"string with spaces\"\n")
|
160
|
+
|
161
|
+
Pliny.log(foo: "string with spaces")
|
162
|
+
end
|
163
|
+
|
164
|
+
it "by default interpolates objects into strings" do
|
165
|
+
expect(@io).to receive(:print).with("foo=message\n")
|
166
|
+
expect(@io).to receive(:print).with("foo=42\n")
|
167
|
+
expect(@io).to receive(:print).with("foo=bar\n")
|
168
|
+
|
169
|
+
Pliny.log(foo: StandardError.new("message"))
|
170
|
+
Pliny.log(foo: 42)
|
171
|
+
|
172
|
+
klass = Class.new do
|
173
|
+
def to_s
|
174
|
+
"bar"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
Pliny.log(foo: klass.new)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "quotes strings that are generated from object interpolation" do
|
181
|
+
expect(@io).to receive(:print).with("foo=\"message with space\"\n")
|
182
|
+
expect(@io).to receive(:print).with("foo=\"bar with space\"\n")
|
183
|
+
|
184
|
+
Pliny.log(foo: StandardError.new("message with space"))
|
185
|
+
|
186
|
+
klass = Class.new do
|
187
|
+
def to_s
|
188
|
+
"bar with space"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
Pliny.log(foo: klass.new)
|
192
|
+
end
|
193
|
+
end
|
133
194
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.28.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -9,28 +9,28 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '5.0'
|
21
18
|
- - ">="
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: 5.0.1
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '7.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - "~>"
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '5.0'
|
31
28
|
- - ">="
|
32
29
|
- !ruby/object:Gem::Version
|
33
30
|
version: 5.0.1
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.0'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: multi_json
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,40 +157,28 @@ dependencies:
|
|
157
157
|
requirements:
|
158
158
|
- - "~>"
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version: '0
|
161
|
-
- - ">="
|
162
|
-
- !ruby/object:Gem::Version
|
163
|
-
version: 0.8.7
|
160
|
+
version: '13.0'
|
164
161
|
type: :development
|
165
162
|
prerelease: false
|
166
163
|
version_requirements: !ruby/object:Gem::Requirement
|
167
164
|
requirements:
|
168
165
|
- - "~>"
|
169
166
|
- !ruby/object:Gem::Version
|
170
|
-
version: '0
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 0.8.7
|
167
|
+
version: '13.0'
|
174
168
|
- !ruby/object:Gem::Dependency
|
175
169
|
name: rack-test
|
176
170
|
requirement: !ruby/object:Gem::Requirement
|
177
171
|
requirements:
|
178
172
|
- - "~>"
|
179
173
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
181
|
-
- - ">="
|
182
|
-
- !ruby/object:Gem::Version
|
183
|
-
version: 0.6.2
|
174
|
+
version: 1.1.0
|
184
175
|
type: :development
|
185
176
|
prerelease: false
|
186
177
|
version_requirements: !ruby/object:Gem::Requirement
|
187
178
|
requirements:
|
188
179
|
- - "~>"
|
189
180
|
- !ruby/object:Gem::Version
|
190
|
-
version:
|
191
|
-
- - ">="
|
192
|
-
- !ruby/object:Gem::Version
|
193
|
-
version: 0.6.2
|
181
|
+
version: 1.1.0
|
194
182
|
- !ruby/object:Gem::Dependency
|
195
183
|
name: rspec
|
196
184
|
requirement: !ruby/object:Gem::Requirement
|
@@ -530,7 +518,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
530
518
|
- !ruby/object:Gem::Version
|
531
519
|
version: '0'
|
532
520
|
requirements: []
|
533
|
-
rubygems_version: 3.0.
|
521
|
+
rubygems_version: 3.0.3
|
534
522
|
signing_key:
|
535
523
|
specification_version: 4
|
536
524
|
summary: Basic tooling to support API apps in Sinatra
|