pliny 0.21.0 → 0.22.0
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 +4 -4
- data/lib/pliny/error_reporters/rollbar.rb +1 -1
- data/lib/pliny/version.rb +1 -1
- data/lib/template/.rubocop.yml +29 -0
- data/lib/template/Gemfile +4 -2
- data/lib/template/Rakefile +2 -1
- data/lib/template/bin/console +7 -7
- data/lib/template/bin/run +3 -1
- data/lib/template/config.ru +1 -1
- data/lib/template/config/config.rb +2 -2
- data/lib/template/config/initializers/database.rb +3 -3
- data/lib/template/config/initializers/rollbar.rb +3 -4
- data/lib/template/config/puma.rb +1 -1
- data/lib/template/lib/application.rb +2 -2
- data/lib/template/lib/endpoints/health.rb +5 -5
- data/lib/template/lib/endpoints/schema.rb +2 -2
- data/lib/template/lib/mediators/base.rb +1 -1
- data/lib/template/lib/routes.rb +9 -5
- data/lib/template/lib/serializers/base.rb +2 -3
- data/lib/template/lib/tasks/rubocop.rake +6 -0
- data/lib/template/lib/tasks/spec.rake +4 -2
- data/lib/template/spec/endpoints/health_spec.rb +16 -16
- data/lib/template/spec/endpoints/schema_spec.rb +2 -2
- data/lib/template/spec/spec_helper.rb +4 -4
- data/lib/template/spec/spec_support/log.rb +5 -3
- data/spec/error_reporters/rollbar_spec.rb +5 -1
- data/spec/integration_spec.rb +9 -11
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ee81425520e48b9096f3d05164ff1793e6e3e8
|
4
|
+
data.tar.gz: dce7f63b5664b66b7ad219d54ed5bb9818a8de9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 622a31e59a1124f435b6954036ce1bb0e3692fd7b998409a68460a91e63d815f17bfc211ab9781f61f95f3a6d58234731d32b208e4f9f26a31b87e100d21d897
|
7
|
+
data.tar.gz: c53473f9fd7bf1289c799007c132fd2a529d27cbafab745f3cc08bbdc5a0137ed2508f00b37cc15313bb4f30373942c52f9a6dd3529379a5b57b0d35e7dae0f8
|
data/lib/pliny/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
5
|
+
# Offense count: 8
|
6
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
7
|
+
# URISchemes: http, https
|
8
|
+
Metrics/LineLength:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
# Offense count: 1
|
12
|
+
# Configuration parameters: Max.
|
13
|
+
RSpec/ExampleLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
Style/ClassVars:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
# Offense count: 6
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/StringLiterals:
|
25
|
+
Enabled: true
|
26
|
+
EnforcedStyle: double_quotes
|
27
|
+
|
28
|
+
Style/FrozenStringLiteralComment:
|
29
|
+
Enabled: false
|
data/lib/template/Gemfile
CHANGED
@@ -4,7 +4,7 @@ ruby "2.3.3"
|
|
4
4
|
gem "multi_json"
|
5
5
|
gem "oj"
|
6
6
|
gem "pg"
|
7
|
-
gem "pliny", "~> 0.
|
7
|
+
gem "pliny", "~> 0.22"
|
8
8
|
gem "pry"
|
9
9
|
gem "puma", "~> 2.16"
|
10
10
|
gem "rack-ssl"
|
@@ -21,13 +21,15 @@ gem "sucker_punch"
|
|
21
21
|
|
22
22
|
group :development, :test do
|
23
23
|
gem "pry-byebug"
|
24
|
+
gem "rubocop", "~> 0.46.0", require: false
|
25
|
+
gem "rubocop-rspec", require: false
|
24
26
|
end
|
25
27
|
|
26
28
|
group :test do
|
27
|
-
gem "simplecov", require: false
|
28
29
|
gem "committee"
|
29
30
|
gem "database_cleaner"
|
30
31
|
gem "dotenv"
|
31
32
|
gem "rack-test"
|
32
33
|
gem "rspec"
|
34
|
+
gem "simplecov", require: false
|
33
35
|
end
|
data/lib/template/Rakefile
CHANGED
data/lib/template/bin/console
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../lib/application"
|
4
4
|
|
5
5
|
def basic_prompt(target_self, nest_level, pry)
|
6
6
|
# override DEPLOYMENT to identify console sessions (eg: staging/production/etc)
|
@@ -9,13 +9,13 @@ def basic_prompt(target_self, nest_level, pry)
|
|
9
9
|
end
|
10
10
|
|
11
11
|
Pry.prompt = [
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
proc do |target_self, nest_level, pry|
|
13
|
+
basic_prompt(target_self, nest_level, pry) + "> "
|
14
|
+
end,
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
proc do |target_self, nest_level, pry|
|
17
|
+
basic_prompt(target_self, nest_level, pry) + "* "
|
18
|
+
end
|
19
19
|
]
|
20
20
|
|
21
21
|
Pry.start
|
data/lib/template/bin/run
CHANGED
data/lib/template/config.ru
CHANGED
@@ -20,9 +20,9 @@ module Config
|
|
20
20
|
# Override -- value is returned or the set default.
|
21
21
|
override :database_timeout, 10, int
|
22
22
|
override :db_pool, 5, int
|
23
|
-
override :deployment,
|
23
|
+
override :deployment, "production", string
|
24
24
|
override :force_ssl, true, bool
|
25
|
-
override :app_env,
|
25
|
+
override :app_env, "production", string
|
26
26
|
override :port, 5000, int
|
27
27
|
override :pretty_json, false, bool
|
28
28
|
override :puma_max_threads, 16, int
|
@@ -1,10 +1,10 @@
|
|
1
1
|
database_setup_proc = lambda do |conn|
|
2
2
|
# identify postgres connections coming from this process in pg_stat_activity
|
3
|
-
process_identifier = ENV["DYNO"] || File.basename($
|
3
|
+
process_identifier = ENV["DYNO"] || File.basename($PROGRAM_NAME).gsub(/\W+/, "_")
|
4
4
|
conn.execute "SET statement_timeout = '#{Config.database_timeout}s'"
|
5
5
|
conn.execute "SET application_name = '#{process_identifier}'"
|
6
6
|
end
|
7
7
|
|
8
8
|
DB = Sequel.connect(Config.database_url,
|
9
|
-
|
10
|
-
|
9
|
+
max_connections: Config.db_pool,
|
10
|
+
after_connect: database_setup_proc)
|
@@ -1,13 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "pliny/error_reporters/rollbar"
|
2
2
|
|
3
3
|
Pliny::ErrorReporters.error_reporters << Pliny::ErrorReporters::Rollbar
|
4
4
|
|
5
5
|
Rollbar.configure do |config|
|
6
|
-
config.enabled = ENV.
|
6
|
+
config.enabled = ENV.key?("ROLLBAR_ACCESS_TOKEN")
|
7
7
|
config.disable_rack_monkey_patch = true
|
8
8
|
config.access_token = ENV["ROLLBAR_ACCESS_TOKEN"]
|
9
|
-
config.environment = ENV[
|
9
|
+
config.environment = ENV["ROLLBAR_ENV"]
|
10
10
|
config.logger = Pliny::RollbarLogger.new
|
11
11
|
config.use_sucker_punch
|
12
12
|
end
|
13
|
-
|
data/lib/template/config/puma.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Endpoints
|
2
2
|
class Health < Base
|
3
|
-
namespace
|
3
|
+
namespace "/health" do
|
4
4
|
get do
|
5
5
|
encode({})
|
6
6
|
end
|
7
7
|
|
8
|
-
get
|
8
|
+
get "/db" do
|
9
9
|
database?
|
10
10
|
database_available?
|
11
11
|
encode({})
|
@@ -14,14 +14,14 @@ module Endpoints
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def database?
|
17
|
-
|
17
|
+
raise Pliny::Errors::NotFound if DB.nil?
|
18
18
|
end
|
19
19
|
|
20
20
|
def database_available?
|
21
|
-
|
21
|
+
raise Pliny::Errors::ServiceUnavailable unless DB.test_connection
|
22
22
|
rescue Sequel::Error => e
|
23
23
|
message = e.message.strip
|
24
|
-
Pliny.log(db: true, health: true, at:
|
24
|
+
Pliny.log(db: true, health: true, at: "exception", message: message)
|
25
25
|
raise Pliny::Errors::ServiceUnavailable
|
26
26
|
end
|
27
27
|
end
|
@@ -3,9 +3,9 @@ module Endpoints
|
|
3
3
|
get "/schema.json" do
|
4
4
|
content_type "application/schema+json"
|
5
5
|
headers["Cache-Control"] = "public, max-age=3600"
|
6
|
-
unless File.
|
6
|
+
unless File.exist?(schema_filename)
|
7
7
|
message = "This application does not have a schema file."
|
8
|
-
raise Pliny::Errors::NotFound
|
8
|
+
raise Pliny::Errors::NotFound, message
|
9
9
|
end
|
10
10
|
File.read(schema_filename)
|
11
11
|
end
|
data/lib/template/lib/routes.rb
CHANGED
@@ -6,11 +6,15 @@ Routes = Rack::Builder.new do
|
|
6
6
|
use Pliny::Middleware::Metrics
|
7
7
|
use Pliny::Middleware::Instruments
|
8
8
|
use Pliny::Middleware::RescueErrors, raise: Config.raise_errors?
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
if Config.timeout.positive?
|
10
|
+
use Rack::Timeout,
|
11
|
+
service_timeout: Config.timeout
|
12
|
+
end
|
13
|
+
if Config.versioning?
|
14
|
+
use Pliny::Middleware::Versioning,
|
15
|
+
default: Config.versioning_default,
|
16
|
+
app_name: Config.versioning_app_name
|
17
|
+
end
|
14
18
|
use Rack::Deflater
|
15
19
|
use Rack::MethodOverride
|
16
20
|
use Rack::SSL if Config.force_ssl?
|
@@ -3,7 +3,7 @@ module Serializers
|
|
3
3
|
@@structures = {}
|
4
4
|
|
5
5
|
def self.structure(type, &blk)
|
6
|
-
@@structures["#{
|
6
|
+
@@structures["#{name}::#{type}"] = blk
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize(type)
|
@@ -11,7 +11,7 @@ module Serializers
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def serialize(object)
|
14
|
-
object.respond_to?(:map) ? object.map{|item| serializer.call(item)} : serializer.call(object)
|
14
|
+
object.respond_to?(:map) ? object.map { |item| serializer.call(item) } : serializer.call(object)
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -19,6 +19,5 @@ module Serializers
|
|
19
19
|
def serializer
|
20
20
|
@@structures["#{self.class.name}::#{@type}"]
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
23
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# define our own version of the spec task because rspec might not be available
|
2
3
|
# in the production environment, so we can't rely on RSpec::Core::RakeTask
|
3
4
|
desc "Run all app specs"
|
@@ -5,6 +6,7 @@ task :spec do
|
|
5
6
|
require "rspec/core"
|
6
7
|
code = RSpec::Core::Runner.run(
|
7
8
|
["./spec"],
|
8
|
-
$stderr, $stdout
|
9
|
-
|
9
|
+
$stderr, $stdout
|
10
|
+
)
|
11
|
+
exit(code) unless code.zero?
|
10
12
|
end
|
@@ -7,48 +7,48 @@ RSpec.describe Endpoints::Health do
|
|
7
7
|
Endpoints::Health
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
12
|
-
get
|
10
|
+
describe "GET /health" do
|
11
|
+
it "returns a 200" do
|
12
|
+
get "/health"
|
13
13
|
assert_equal(200, last_response.status)
|
14
|
-
assert_equal(
|
15
|
-
assert_equal(2, last_response.headers[
|
14
|
+
assert_equal("application/json;charset=utf-8", last_response.headers["Content-Type"])
|
15
|
+
assert_equal(2, last_response.headers["Content-Length"].to_i)
|
16
16
|
assert_equal({}, MultiJson.decode(last_response.body))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
21
|
-
it
|
20
|
+
describe "GET /health/db" do
|
21
|
+
it "raises a 404 when no database is available" do
|
22
22
|
allow(DB).to receive(:nil?).and_return(true)
|
23
23
|
|
24
24
|
assert_raises Pliny::Errors::NotFound do
|
25
|
-
get
|
25
|
+
get "/health/db"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "raises a 503 on Sequel exceptions" do
|
30
30
|
allow(DB).to receive(:test_connection).and_raise(Sequel::Error)
|
31
31
|
|
32
32
|
assert_raises Pliny::Errors::ServiceUnavailable do
|
33
|
-
get
|
33
|
+
get "/health/db"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it "raises a 503 when connection testing fails" do
|
38
38
|
allow(DB).to receive(:test_connection).and_return(false)
|
39
39
|
|
40
40
|
assert_raises Pliny::Errors::ServiceUnavailable do
|
41
|
-
get
|
41
|
+
get "/health/db"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "returns a 200" do
|
46
46
|
allow(DB).to receive(:test_connection).and_return(true)
|
47
47
|
|
48
|
-
get
|
48
|
+
get "/health/db"
|
49
49
|
assert_equal(200, last_response.status)
|
50
|
-
assert_equal(
|
51
|
-
assert_equal(2, last_response.headers[
|
50
|
+
assert_equal("application/json;charset=utf-8", last_response.headers["Content-Type"])
|
51
|
+
assert_equal(2, last_response.headers["Content-Length"].to_i)
|
52
52
|
assert_equal({}, MultiJson.decode(last_response.body))
|
53
53
|
end
|
54
54
|
end
|
@@ -3,10 +3,10 @@ require "spec_helper"
|
|
3
3
|
RSpec.describe Endpoints::Schema do
|
4
4
|
include Rack::Test::Methods
|
5
5
|
|
6
|
-
let(:schema_filename) { "#{Config.root}/schema/schema.json" }
|
7
|
-
|
8
6
|
subject(:get_schema) { get "/schema.json" }
|
9
7
|
|
8
|
+
let(:schema_filename) { "#{Config.root}/schema/schema.json" }
|
9
|
+
|
10
10
|
context "without a schema.json" do
|
11
11
|
before do
|
12
12
|
allow(File).to receive(:exists?).and_return(false)
|
@@ -10,7 +10,7 @@ ENV["RACK_ENV"] = "test"
|
|
10
10
|
require "bundler"
|
11
11
|
require "dotenv"
|
12
12
|
Bundler.require(:default, :test)
|
13
|
-
Dotenv.load(
|
13
|
+
Dotenv.load(".env.test")
|
14
14
|
|
15
15
|
# Get only App Config first, to avoid pulling in libraries until
|
16
16
|
# spec_support has a chance to run, which is important for at least
|
@@ -29,7 +29,7 @@ RSpec.configure do |config|
|
|
29
29
|
end
|
30
30
|
|
31
31
|
config.before :all do
|
32
|
-
load(
|
32
|
+
load("db/seeds.rb") if File.exist?("db/seeds.rb")
|
33
33
|
end
|
34
34
|
|
35
35
|
config.before :each do
|
@@ -49,10 +49,10 @@ RSpec.configure do |config|
|
|
49
49
|
# order dependency and want to debug it, you can fix the order by providing
|
50
50
|
# the seed, which is printed after each run.
|
51
51
|
# --seed 1234
|
52
|
-
config.order =
|
52
|
+
config.order = "random"
|
53
53
|
|
54
54
|
# the rack app to be tested with rack-test:
|
55
55
|
def app
|
56
|
-
@rack_app ||
|
56
|
+
@rack_app || raise("Missing @rack_app")
|
57
57
|
end
|
58
58
|
end
|
@@ -8,7 +8,7 @@ describe Pliny::ErrorReporters::Rollbar do
|
|
8
8
|
describe "#notify" do
|
9
9
|
let(:exception) { StandardError.new("Something went wrong") }
|
10
10
|
let(:context) { {} }
|
11
|
-
let(:rack_env) {
|
11
|
+
let(:rack_env) { { "rack.input" => StringIO.new } }
|
12
12
|
|
13
13
|
subject(:notify) do
|
14
14
|
reporter.notify(exception, context: context, rack_env: rack_env)
|
@@ -41,6 +41,10 @@ describe Pliny::ErrorReporters::Rollbar do
|
|
41
41
|
context "given an empty rack_env" do
|
42
42
|
let(:rack_env) { {} }
|
43
43
|
|
44
|
+
it "expects rack_env to be a hash" do
|
45
|
+
assert_kind_of(Hash, rack_env)
|
46
|
+
end
|
47
|
+
|
44
48
|
it "reports to Rollbar with an empty scope" do
|
45
49
|
notify
|
46
50
|
expect(Rollbar).to have_received(:scoped).once.with({})
|
data/spec/integration_spec.rb
CHANGED
@@ -7,34 +7,36 @@ describe "Pliny integration test" do
|
|
7
7
|
Dir.chdir("/tmp/plinytest")
|
8
8
|
|
9
9
|
bash "pliny-new myapp"
|
10
|
-
|
10
|
+
|
11
|
+
Dir.chdir("/tmp/plinytest/myapp")
|
12
|
+
bash "bin/setup"
|
11
13
|
end
|
12
14
|
|
13
15
|
describe "bin/setup" do
|
14
16
|
it "generates .env" do
|
15
|
-
assert File.exists?("
|
17
|
+
assert File.exists?("./.env")
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
describe "pliny-generate scaffold" do
|
20
22
|
before(:all) do
|
21
|
-
|
23
|
+
bash "pliny-generate scaffold artist"
|
22
24
|
end
|
23
25
|
|
24
26
|
it "creates the model file" do
|
25
|
-
assert File.exists?("./
|
27
|
+
assert File.exists?("./lib/models/artist.rb")
|
26
28
|
end
|
27
29
|
|
28
30
|
it "creates the endpoint file" do
|
29
|
-
assert File.exists?("./
|
31
|
+
assert File.exists?("./lib/endpoints/artists.rb")
|
30
32
|
end
|
31
33
|
|
32
34
|
it "creates the serializer file" do
|
33
|
-
assert File.exists?("./
|
35
|
+
assert File.exists?("./lib/serializers/artist.rb")
|
34
36
|
end
|
35
37
|
|
36
38
|
it "creates the schema file" do
|
37
|
-
assert File.exists?("./
|
39
|
+
assert File.exists?("./schema/schemata/artist.yaml")
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
@@ -46,8 +48,4 @@ describe "Pliny integration test" do
|
|
46
48
|
raise "Failed to run #{cmd}"
|
47
49
|
end
|
48
50
|
end
|
49
|
-
|
50
|
-
def bash_app(cmd)
|
51
|
-
bash "cd myapp && #{cmd}"
|
52
|
-
end
|
53
51
|
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.22.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:
|
12
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -339,6 +339,26 @@ dependencies:
|
|
339
339
|
- - ">="
|
340
340
|
- !ruby/object:Gem::Version
|
341
341
|
version: 4.9.0
|
342
|
+
- !ruby/object:Gem::Dependency
|
343
|
+
name: rubocop
|
344
|
+
requirement: !ruby/object:Gem::Requirement
|
345
|
+
requirements:
|
346
|
+
- - "~>"
|
347
|
+
- !ruby/object:Gem::Version
|
348
|
+
version: '0.46'
|
349
|
+
- - ">="
|
350
|
+
- !ruby/object:Gem::Version
|
351
|
+
version: 0.46.0
|
352
|
+
type: :development
|
353
|
+
prerelease: false
|
354
|
+
version_requirements: !ruby/object:Gem::Requirement
|
355
|
+
requirements:
|
356
|
+
- - "~>"
|
357
|
+
- !ruby/object:Gem::Version
|
358
|
+
version: '0.46'
|
359
|
+
- - ">="
|
360
|
+
- !ruby/object:Gem::Version
|
361
|
+
version: 0.46.0
|
342
362
|
description: Pliny is a set of base classes and helpers to help developers write excellent
|
343
363
|
APIs in Sinatra
|
344
364
|
email:
|
@@ -410,6 +430,7 @@ files:
|
|
410
430
|
- lib/template/.env.test.erb
|
411
431
|
- lib/template/.gitignore
|
412
432
|
- lib/template/.rspec
|
433
|
+
- lib/template/.rubocop.yml
|
413
434
|
- lib/template/.ruby-version
|
414
435
|
- lib/template/Gemfile
|
415
436
|
- lib/template/LICENSE
|
@@ -438,6 +459,7 @@ files:
|
|
438
459
|
- lib/template/lib/mediators/base.rb
|
439
460
|
- lib/template/lib/routes.rb
|
440
461
|
- lib/template/lib/serializers/base.rb
|
462
|
+
- lib/template/lib/tasks/rubocop.rake
|
441
463
|
- lib/template/lib/tasks/spec.rake
|
442
464
|
- lib/template/schema/meta.json
|
443
465
|
- lib/template/schema/schemata/.gitkeep
|