pliny 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/README.md +1 -2
- data/lib/pliny/log.rb +2 -10
- data/lib/pliny/tasks/db.rake +19 -8
- data/lib/pliny/version.rb +1 -1
- data/{test/commands/creator_test.rb → spec/commands/creator_spec.rb} +1 -1
- data/{test/commands/generator/base_test.rb → spec/commands/generator/base_spec.rb} +1 -1
- data/{test/commands/generator/endpoint_test.rb → spec/commands/generator/endpoint_spec.rb} +1 -1
- data/{test/commands/generator_test.rb → spec/commands/generator_spec.rb} +1 -1
- data/{test/errors_test.rb → spec/errors_spec.rb} +1 -1
- data/{test/extensions/instruments_test.rb → spec/extensions/instruments_spec.rb} +1 -1
- data/{test/integration_test.rb → spec/integration_spec.rb} +1 -1
- data/{test/log_test.rb → spec/log_spec.rb} +16 -8
- data/{test/middleware/cors_test.rb → spec/middleware/cors_spec.rb} +1 -1
- data/{test/middleware/request_id_test.rb → spec/middleware/request_id_spec.rb} +1 -1
- data/{test/middleware/request_store_test.rb → spec/middleware/request_store_spec.rb} +1 -1
- data/{test/middleware/rescue_errors_test.rb → spec/middleware/rescue_errors_spec.rb} +1 -1
- data/{test/middleware/timeout_test.rb → spec/middleware/timeout_spec.rb} +1 -1
- data/{test/middleware/versioning_test.rb → spec/middleware/versioning_spec.rb} +6 -1
- data/{test/request_store_test.rb → spec/request_store_spec.rb} +1 -1
- data/{test/router_test.rb → spec/router_spec.rb} +1 -1
- data/spec/spec_helper.rb +26 -0
- data/template/.ruby-version +1 -1
- data/template/Gemfile +2 -3
- data/template/Gemfile.lock +12 -13
- metadata +20 -22
- data/lib/pliny/tasks/test.rake +0 -8
- data/test/test_helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmVlMTRhYThlZWVjYzA2MjNlYjZjZDY5NTkyMDY5YmE5NWEwNDAyMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
MTczNDRhNTY2N2UwMmUyY2I4YWQ5NDFlN2MwYzhlN2JlNTVhOWIwYw==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTM1OTZkNmMxMDcwMTg4ZWVkYWFkN2MxMjQ3MWM5MzdhNmE4M2NkZmYxMjA4
|
10
|
+
YzM5MGRmZmFlM2YyMzJmMTE3YzM3ZGVmMjYxNTk3YWRjOTdhODA4YTcwY2Ew
|
11
|
+
OWQyNjQ3YTlhZmZmYTBjN2UxMjFlMDEwZGRlMTA5NTI0OTJhYmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGY5YmExZmE5YTQwMGQ4MWNiNzkyYTMwZDA1NjNmZTI5YmM1ZWY4YTFjYTQx
|
14
|
+
ZDIwZDkxZDdjNmY1ZjlkZDQ2Y2EyM2NlZTNhY2NmNjQ1N2M1MzY4MTViN2Q0
|
15
|
+
ZmIxZmY1MTQ0MjIyNmNiOGE2OTQwZTk3YzJkOTBiMzQwNWM5Mjk=
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ And gems/helpers to tie these together and support operations:
|
|
16
16
|
|
17
17
|
- [CORS middleware](lib/pliny/middleware/cors.rb) to allow JS developers to consume your API
|
18
18
|
- [Rollbar](https://www.rollbar.com/) for tracking exceptions
|
19
|
-
- [Log helper](
|
19
|
+
- [Log helper](spec/log_spec.rb) that logs in [data format](https://www.youtube.com/watch?v=rpmc-wHFUBs) [to stdout](https://adam.heroku.com/past/2011/4/1/logs_are_streams_not_files)
|
20
20
|
- [Mediators](http://brandur.org/mediator) to help encapsulate more complex interactions
|
21
21
|
- [Rspec](https://github.com/rspec/rspec) for lean and fast testing
|
22
22
|
- [Puma](http://puma.io/) as the web server, [configured for optimal performance on Heroku](https://github.com/interagent/pliny-template/blob/master/config/puma.rb)
|
@@ -121,7 +121,6 @@ rake db:schema:merge # Merges migrations into schema and removes them
|
|
121
121
|
rake db:seed # Seed the database with data
|
122
122
|
rake db:setup # Setup the database
|
123
123
|
rake schema # Rebuild schema.json
|
124
|
-
rake test # Run tests
|
125
124
|
```
|
126
125
|
|
127
126
|
### Commands
|
data/lib/pliny/log.rb
CHANGED
@@ -10,7 +10,7 @@ module Pliny
|
|
10
10
|
self.local_context = old.merge(data)
|
11
11
|
res = block.call
|
12
12
|
ensure
|
13
|
-
local_context = old
|
13
|
+
self.local_context = old
|
14
14
|
res
|
15
15
|
end
|
16
16
|
|
@@ -39,11 +39,7 @@ module Pliny
|
|
39
39
|
def log_to_stream(stream, data, &block)
|
40
40
|
unless block
|
41
41
|
str = unparse(data)
|
42
|
-
|
43
|
-
stream.puts str
|
44
|
-
else
|
45
|
-
mtx.synchronize { stream.puts str }
|
46
|
-
end
|
42
|
+
stream.print(str + "\n")
|
47
43
|
else
|
48
44
|
data = data.dup
|
49
45
|
start = Time.now
|
@@ -61,10 +57,6 @@ module Pliny
|
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
64
|
-
def mtx
|
65
|
-
@mtx ||= Mutex.new
|
66
|
-
end
|
67
|
-
|
68
60
|
def quote_string(k, v)
|
69
61
|
# try to find a quote style that fits
|
70
62
|
if !v.include?('"')
|
data/lib/pliny/tasks/db.rake
CHANGED
@@ -30,7 +30,7 @@ namespace :db do
|
|
30
30
|
database_urls.each do |database_url|
|
31
31
|
db = Sequel.connect(database_url)
|
32
32
|
db.tables.each do |table|
|
33
|
-
db.run(%{DROP TABLE "#{table}"})
|
33
|
+
db.run(%{DROP TABLE "#{table}" CASCADE})
|
34
34
|
end
|
35
35
|
puts "Nuked `#{name_from_uri(database_url)}`"
|
36
36
|
end
|
@@ -78,11 +78,15 @@ namespace :db do
|
|
78
78
|
namespace :schema do
|
79
79
|
desc "Load the database schema"
|
80
80
|
task :load do
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
if File.exists?("./db/schema.sql")
|
82
|
+
schema = File.read("./db/schema.sql")
|
83
|
+
database_urls.each do |database_url|
|
84
|
+
db = Sequel.connect(database_url)
|
85
|
+
db.run(schema)
|
86
|
+
puts "Loaded `#{name_from_uri(database_url)}`"
|
87
|
+
end
|
88
|
+
else
|
89
|
+
puts "Skipped schema load, schema.sql not present"
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
@@ -98,8 +102,15 @@ namespace :db do
|
|
98
102
|
# replay such statements in certain production databases
|
99
103
|
schema.gsub!(/^COMMENT ON EXTENSION.*\n/, "")
|
100
104
|
|
101
|
-
|
105
|
+
# add migrations used to compose this schema
|
106
|
+
db = Sequel.connect(database_urls.first)
|
107
|
+
if db.table_exists?(:schema_migrations)
|
108
|
+
db[:schema_migrations].each do |migration|
|
109
|
+
schema << db[:schema_migrations].insert_sql(migration) + ";\n"
|
110
|
+
end
|
111
|
+
end
|
102
112
|
|
113
|
+
File.open(file, "w") { |f| f.puts schema }
|
103
114
|
puts "Dumped `#{name_from_uri(database_url)}` to #{file}"
|
104
115
|
end
|
105
116
|
|
@@ -111,7 +122,7 @@ namespace :db do
|
|
111
122
|
end
|
112
123
|
|
113
124
|
desc "Setup the database"
|
114
|
-
task :setup => [:drop, :create]
|
125
|
+
task :setup => [:drop, :create, :migrate]
|
115
126
|
|
116
127
|
private
|
117
128
|
|
data/lib/pliny/version.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
require "
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pliny::Log do
|
4
4
|
before do
|
5
5
|
@io = StringIO.new
|
6
6
|
Pliny.stdout = @io
|
7
|
-
stub(@io).
|
7
|
+
stub(@io).print
|
8
8
|
end
|
9
9
|
|
10
10
|
it "logs in structured format" do
|
11
|
-
mock(@io).
|
11
|
+
mock(@io).print "foo=bar baz=42\n"
|
12
12
|
Pliny.log(foo: "bar", baz: 42)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "supports blocks to log stages and elapsed" do
|
16
|
-
mock(@io).
|
17
|
-
mock(@io).
|
16
|
+
mock(@io).print "foo=bar at=start\n"
|
17
|
+
mock(@io).print "foo=bar at=finish elapsed=0.000\n"
|
18
18
|
Pliny.log(foo: "bar") do
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
it "merges context from RequestStore" do
|
23
23
|
Pliny::RequestStore.store[:log_context] = { app: "pliny" }
|
24
|
-
mock(@io).
|
24
|
+
mock(@io).print "app=pliny foo=bar\n"
|
25
25
|
Pliny.log(foo: "bar")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "supports a context" do
|
29
|
-
mock(@io).
|
29
|
+
mock(@io).print "app=pliny foo=bar\n"
|
30
30
|
Pliny.context(app: "pliny") do
|
31
31
|
Pliny.log(foo: "bar")
|
32
32
|
end
|
@@ -34,10 +34,18 @@ describe Pliny::Log do
|
|
34
34
|
|
35
35
|
it "local context does not overwrite global" do
|
36
36
|
Pliny::RequestStore.store[:log_context] = { app: "pliny" }
|
37
|
-
mock(@io).
|
37
|
+
mock(@io).print "app=not_pliny foo=bar\n"
|
38
38
|
Pliny.context(app: "not_pliny") do
|
39
39
|
Pliny.log(foo: "bar")
|
40
40
|
end
|
41
41
|
assert Pliny::RequestStore.store[:log_context][:app] = "pliny"
|
42
42
|
end
|
43
|
+
|
44
|
+
it "local context does not propagate outside" do
|
45
|
+
Pliny::RequestStore.store[:log_context] = { app: "pliny" }
|
46
|
+
mock(@io).print "app=pliny foo=bar\n"
|
47
|
+
Pliny.context(app: "not_pliny", test: 123) do
|
48
|
+
end
|
49
|
+
Pliny.log(foo: "bar")
|
50
|
+
end
|
43
51
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# make sure this is set before Sinatra is required
|
2
|
+
ENV["RACK_ENV"] = "test"
|
3
|
+
|
4
|
+
require "bundler"
|
5
|
+
Bundler.require(:default, :test)
|
6
|
+
|
7
|
+
require_relative "../lib/pliny"
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include Rack::Test::Methods
|
11
|
+
|
12
|
+
config.expect_with :minitest
|
13
|
+
config.mock_with :rr
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
config.before :each do
|
18
|
+
Pliny::RequestStore.clear!
|
19
|
+
end
|
20
|
+
|
21
|
+
# Run specs in random order to surface order dependencies. If you find an
|
22
|
+
# order dependency and want to debug it, you can fix the order by providing
|
23
|
+
# the seed, which is printed after each run.
|
24
|
+
# --seed 1234
|
25
|
+
config.order = 'random'
|
26
|
+
end
|
data/template/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.4
|
data/template/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
|
-
ruby "2.1.
|
2
|
+
ruby "2.1.4"
|
3
3
|
|
4
4
|
gem "multi_json"
|
5
5
|
gem "oj"
|
@@ -24,8 +24,7 @@ group :development, :test do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
group :development do
|
27
|
-
gem
|
28
|
-
gem "foreman"
|
27
|
+
gem "dotenv"
|
29
28
|
end
|
30
29
|
|
31
30
|
group :test do
|
data/template/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (4.1.
|
4
|
+
activesupport (4.1.6)
|
5
5
|
i18n (~> 0.6, >= 0.6.9)
|
6
6
|
json (~> 1.7, >= 1.7.7)
|
7
7
|
minitest (~> 5.1)
|
@@ -23,18 +23,16 @@ GEM
|
|
23
23
|
diff-lcs (1.2.5)
|
24
24
|
dotenv (0.7.0)
|
25
25
|
erubis (2.7.0)
|
26
|
-
|
27
|
-
|
28
|
-
thor (~> 0.17.0)
|
29
|
-
http_accept (0.1.5)
|
30
|
-
i18n (0.6.9)
|
26
|
+
http_accept (0.1.6)
|
27
|
+
i18n (0.6.11)
|
31
28
|
json (1.8.1)
|
29
|
+
json_schema (0.3.0)
|
32
30
|
method_source (0.8.2)
|
33
|
-
minitest (5.
|
31
|
+
minitest (5.4.2)
|
34
32
|
multi_json (1.10.1)
|
35
33
|
oj (2.9.0)
|
36
34
|
pg (0.17.1)
|
37
|
-
pliny (0.
|
35
|
+
pliny (0.4.0)
|
38
36
|
activesupport (~> 4.1, >= 4.1.0)
|
39
37
|
http_accept (~> 0.1, >= 0.1.5)
|
40
38
|
multi_json (~> 1.9, >= 1.9.3)
|
@@ -43,8 +41,10 @@ GEM
|
|
43
41
|
sequel (~> 4.9, >= 4.9.0)
|
44
42
|
sinatra (~> 1.4, >= 1.4.5)
|
45
43
|
sinatra-router (~> 0.2, >= 0.2.3)
|
46
|
-
|
44
|
+
thor (~> 0.19, >= 0.19.1)
|
45
|
+
prmd (0.6.2)
|
47
46
|
erubis (~> 2.7)
|
47
|
+
json_schema (~> 0.1)
|
48
48
|
pry (0.9.12.6)
|
49
49
|
coderay (~> 1.0)
|
50
50
|
method_source (~> 0.8)
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
rspec-mocks (3.0.1)
|
80
80
|
rspec-support (~> 3.0.0)
|
81
81
|
rspec-support (3.0.0)
|
82
|
-
sequel (4.
|
82
|
+
sequel (4.15.0)
|
83
83
|
sequel-paranoid (0.4.3)
|
84
84
|
sequel
|
85
85
|
sequel_pg (1.6.9)
|
@@ -101,11 +101,11 @@ GEM
|
|
101
101
|
slop (3.5.0)
|
102
102
|
sucker_punch (1.0.5)
|
103
103
|
celluloid (~> 0.15.2)
|
104
|
-
thor (0.
|
104
|
+
thor (0.19.1)
|
105
105
|
thread_safe (0.3.4)
|
106
106
|
tilt (1.4.1)
|
107
107
|
timers (1.1.0)
|
108
|
-
tzinfo (1.2.
|
108
|
+
tzinfo (1.2.2)
|
109
109
|
thread_safe (~> 0.1)
|
110
110
|
yard (0.8.7.4)
|
111
111
|
|
@@ -116,7 +116,6 @@ DEPENDENCIES
|
|
116
116
|
committee
|
117
117
|
database_cleaner
|
118
118
|
dotenv
|
119
|
-
foreman
|
120
119
|
multi_json
|
121
120
|
oj
|
122
121
|
pg
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -326,7 +326,6 @@ files:
|
|
326
326
|
- lib/pliny/tasks.rb
|
327
327
|
- lib/pliny/tasks/db.rake
|
328
328
|
- lib/pliny/tasks/schema.rake
|
329
|
-
- lib/pliny/tasks/test.rake
|
330
329
|
- lib/pliny/templates/endpoint.erb
|
331
330
|
- lib/pliny/templates/endpoint_acceptance_test.erb
|
332
331
|
- lib/pliny/templates/endpoint_scaffold.erb
|
@@ -342,23 +341,23 @@ files:
|
|
342
341
|
- lib/pliny/templates/serializer_test.erb
|
343
342
|
- lib/pliny/utils.rb
|
344
343
|
- lib/pliny/version.rb
|
345
|
-
-
|
346
|
-
-
|
347
|
-
-
|
348
|
-
-
|
349
|
-
-
|
350
|
-
-
|
351
|
-
-
|
352
|
-
-
|
353
|
-
-
|
354
|
-
-
|
355
|
-
-
|
356
|
-
-
|
357
|
-
-
|
358
|
-
-
|
359
|
-
-
|
360
|
-
-
|
361
|
-
-
|
344
|
+
- spec/commands/creator_spec.rb
|
345
|
+
- spec/commands/generator/base_spec.rb
|
346
|
+
- spec/commands/generator/endpoint_spec.rb
|
347
|
+
- spec/commands/generator_spec.rb
|
348
|
+
- spec/errors_spec.rb
|
349
|
+
- spec/extensions/instruments_spec.rb
|
350
|
+
- spec/integration_spec.rb
|
351
|
+
- spec/log_spec.rb
|
352
|
+
- spec/middleware/cors_spec.rb
|
353
|
+
- spec/middleware/request_id_spec.rb
|
354
|
+
- spec/middleware/request_store_spec.rb
|
355
|
+
- spec/middleware/rescue_errors_spec.rb
|
356
|
+
- spec/middleware/timeout_spec.rb
|
357
|
+
- spec/middleware/versioning_spec.rb
|
358
|
+
- spec/request_store_spec.rb
|
359
|
+
- spec/router_spec.rb
|
360
|
+
- spec/spec_helper.rb
|
362
361
|
- template/.env.sample
|
363
362
|
- template/.env.test
|
364
363
|
- template/.gitignore
|
@@ -412,9 +411,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
412
411
|
version: '0'
|
413
412
|
requirements: []
|
414
413
|
rubyforge_project:
|
415
|
-
rubygems_version: 2.
|
414
|
+
rubygems_version: 2.2.2
|
416
415
|
signing_key:
|
417
416
|
specification_version: 4
|
418
417
|
summary: Basic tooling to support API apps in Sinatra
|
419
418
|
test_files: []
|
420
|
-
has_rdoc:
|
data/lib/pliny/tasks/test.rake
DELETED
data/test/test_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# make sure this is set before Sinatra is required
|
2
|
-
ENV["RACK_ENV"] = "test"
|
3
|
-
|
4
|
-
require "bundler"
|
5
|
-
Bundler.require(:default, :test)
|
6
|
-
|
7
|
-
require "minitest/autorun"
|
8
|
-
require "rr"
|
9
|
-
|
10
|
-
require_relative "../lib/pliny"
|
11
|
-
|
12
|
-
class MiniTest::Spec
|
13
|
-
include Rack::Test::Methods
|
14
|
-
|
15
|
-
before do
|
16
|
-
Pliny::RequestStore.clear!
|
17
|
-
end
|
18
|
-
end
|