pliny 1.2.0 → 2.0.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/bin/pliny-generate +2 -1
- data/bin/pliny-new +2 -1
- data/bin/pliny-update +2 -1
- data/lib/pliny/canonical_log_line_helpers.rb +2 -0
- data/lib/pliny/commands/creator.rb +13 -12
- data/lib/pliny/commands/generator/base.rb +11 -9
- data/lib/pliny/commands/generator/endpoint.rb +19 -17
- data/lib/pliny/commands/generator/mediator.rb +7 -5
- data/lib/pliny/commands/generator/migration.rb +4 -2
- data/lib/pliny/commands/generator/model.rb +11 -9
- data/lib/pliny/commands/generator/schema.rb +4 -2
- data/lib/pliny/commands/generator/serializer.rb +7 -5
- data/lib/pliny/commands/generator.rb +19 -17
- data/lib/pliny/commands/updater.rb +5 -3
- data/lib/pliny/config_helpers.rb +10 -35
- data/lib/pliny/db_support.rb +21 -21
- data/lib/pliny/error_reporters/rollbar.rb +5 -3
- data/lib/pliny/error_reporters/sentry.rb +40 -0
- data/lib/pliny/error_reporters.rb +5 -5
- data/lib/pliny/errors.rb +46 -44
- data/lib/pliny/helpers/encode.rb +4 -2
- data/lib/pliny/helpers/params.rb +2 -0
- data/lib/pliny/helpers/serialize.rb +6 -4
- data/lib/pliny/helpers/zulu_time.rb +3 -1
- data/lib/pliny/log.rb +26 -25
- data/lib/pliny/metrics/backends/logger.rb +5 -3
- data/lib/pliny/metrics.rb +4 -2
- data/lib/pliny/middleware/canonical_log_line.rb +5 -3
- data/lib/pliny/middleware/cors.rb +13 -12
- data/lib/pliny/middleware/instruments.rb +9 -7
- data/lib/pliny/middleware/metrics.rb +3 -1
- data/lib/pliny/middleware/request_id.rb +4 -2
- data/lib/pliny/middleware/request_store/clear.rb +3 -1
- data/lib/pliny/middleware/request_store/seed.rb +3 -1
- data/lib/pliny/middleware/rescue_errors.rb +2 -0
- data/lib/pliny/middleware/versioning.rb +11 -11
- data/lib/pliny/request_store.rb +4 -2
- data/lib/pliny/rollbar_logger.rb +6 -4
- data/lib/pliny/router.rb +3 -2
- data/lib/pliny/tasks/db.rake +3 -1
- data/lib/pliny/tasks/schema.rake +3 -1
- data/lib/pliny/tasks.rb +2 -0
- data/lib/pliny/utils.rb +4 -2
- data/lib/pliny/version.rb +3 -1
- data/lib/pliny.rb +2 -0
- data/lib/template/{.rubocop.yml → .rubocop_template.yml} +1 -5
- data/lib/template/Gemfile +7 -4
- data/lib/template/Rakefile +1 -0
- data/lib/template/bin/console +2 -1
- data/lib/template/bin/run +4 -1
- data/lib/template/config/config.rb +18 -16
- data/lib/template/config/initializers/database.rb +4 -2
- data/lib/template/config/initializers/log.rb +2 -0
- data/lib/template/config/initializers/metrics.rb +2 -0
- data/lib/template/config/initializers/sentry.rb +14 -0
- data/lib/template/config/puma.rb +3 -1
- data/lib/template/config.ru +2 -0
- data/lib/template/db/seeds.rb +2 -0
- data/lib/template/lib/application.rb +2 -0
- data/lib/template/lib/endpoints/base.rb +2 -0
- data/lib/template/lib/endpoints/health.rb +2 -0
- data/lib/template/lib/endpoints/root.rb +2 -0
- data/lib/template/lib/endpoints/schema.rb +2 -0
- data/lib/template/lib/initializer.rb +6 -4
- data/lib/template/lib/mediators/base.rb +2 -0
- data/lib/template/lib/routes.rb +8 -6
- data/lib/template/lib/serializers/base.rb +2 -0
- data/lib/template/lib/tasks/rubocop.rake +2 -0
- data/lib/template/lib/tasks/spec.rake +2 -1
- data/lib/template/spec/endpoints/health_spec.rb +2 -0
- data/lib/template/spec/endpoints/schema_spec.rb +2 -0
- data/lib/template/spec/spec_helper.rb +2 -0
- data/lib/template/spec/spec_support/auto_define_rack_app.rb +2 -0
- data/lib/template/spec/spec_support/coverage.rb +2 -0
- data/lib/template/spec/spec_support/log.rb +2 -0
- data/spec/canonical_log_line_helpers_spec.rb +10 -8
- data/spec/commands/creator_spec.rb +3 -0
- data/spec/commands/generator/base_spec.rb +61 -59
- data/spec/commands/generator/endpoint_spec.rb +16 -15
- data/spec/commands/generator/mediator_spec.rb +11 -9
- data/spec/commands/generator/migration_spec.rb +7 -5
- data/spec/commands/generator/model_spec.rb +13 -11
- data/spec/commands/generator/schema_spec.rb +29 -28
- data/spec/commands/generator/serializer_spec.rb +11 -9
- data/spec/commands/generator_spec.rb +64 -62
- data/spec/commands/updater_spec.rb +2 -0
- data/spec/config_helpers_spec.rb +7 -85
- data/spec/db_support_spec.rb +46 -44
- data/spec/error_reporters/rollbar_spec.rb +8 -6
- data/spec/error_reporters/sentry_spec.rb +83 -0
- data/spec/error_reporters_spec.rb +4 -2
- data/spec/errors_spec.rb +4 -1
- data/spec/helpers/encode_spec.rb +2 -0
- data/spec/helpers/params_spec.rb +9 -7
- data/spec/helpers/serialize_spec.rb +11 -7
- data/spec/helpers/zulu_time_spec.rb +6 -4
- data/spec/integration_spec.rb +14 -12
- data/spec/log_spec.rb +8 -6
- data/spec/metrics/backends/logger_spec.rb +10 -6
- data/spec/metrics_spec.rb +15 -13
- data/spec/middleware/canonical_log_line_spec.rb +5 -2
- data/spec/middleware/cors_spec.rb +2 -0
- data/spec/middleware/instruments_spec.rb +10 -8
- data/spec/middleware/metrics_spec.rb +3 -1
- data/spec/middleware/request_id_spec.rb +2 -0
- data/spec/middleware/request_store/clear_spec.rb +2 -0
- data/spec/middleware/request_store/seed_spec.rb +2 -0
- data/spec/middleware/rescue_errors_spec.rb +13 -13
- data/spec/middleware/versioning_spec.rb +22 -20
- data/spec/request_store_spec.rb +3 -1
- data/spec/rollbar_logger_spec.rb +11 -9
- data/spec/router_spec.rb +9 -7
- data/spec/spec_helper.rb +3 -1
- data/spec/support/config.rb +2 -0
- data/spec/support/endpoints.rb +2 -0
- metadata +91 -100
- data/lib/template/config/initializers/rollbar.rb +0 -12
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# please add changes here to core's Instruments as well
|
|
2
4
|
|
|
3
5
|
module Pliny::Middleware
|
|
@@ -47,8 +49,8 @@ module Pliny::Middleware
|
|
|
47
49
|
# field as to whether it should be prefixed with `X-` or not. API went
|
|
48
50
|
# with no prefix, but Hermes went with one. Support both formats on
|
|
49
51
|
# input.
|
|
50
|
-
%w
|
|
51
|
-
if ids = env[key]
|
|
52
|
+
%w[HTTP_REQUEST_ID HTTP_X_REQUEST_ID].inject([]) do |request_ids, key|
|
|
53
|
+
if (ids = env[key])
|
|
52
54
|
request_ids += ids.split(",")
|
|
53
55
|
end
|
|
54
56
|
request_ids
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "http_accept"
|
|
2
4
|
|
|
3
5
|
module Pliny::Middleware
|
|
4
6
|
class Versioning
|
|
5
|
-
def initialize(app, options={})
|
|
7
|
+
def initialize(app, options = {})
|
|
6
8
|
@app = app
|
|
7
9
|
@default = options[:default] || raise("missing=default")
|
|
8
10
|
@app_name = options[:app_name] || raise("missing=app_name")
|
|
@@ -22,17 +24,15 @@ module Pliny::Middleware
|
|
|
22
24
|
version = nil
|
|
23
25
|
media_types.map! do |media_type|
|
|
24
26
|
if accept_headers.include?(media_type.format)
|
|
25
|
-
unless media_type.params[
|
|
26
|
-
error = { id: :bad_version, message:
|
|
27
|
-
Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`.
|
|
28
|
-
|
|
27
|
+
unless media_type.params["version"]
|
|
28
|
+
error = { id: :bad_version, message: <<~EOS }
|
|
29
|
+
Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`.
|
|
30
|
+
EOS
|
|
29
31
|
return [400, { "content-type" => "application/json; charset=utf-8" },
|
|
30
|
-
[JSON.generate(error)]]
|
|
32
|
+
[JSON.generate(error)],]
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
version = media_type.params["version"]
|
|
35
|
-
end
|
|
35
|
+
version ||= media_type.params["version"]
|
|
36
36
|
|
|
37
37
|
# replace the MIME with a simplified version for easier
|
|
38
38
|
# parsing down the stack
|
|
@@ -41,7 +41,7 @@ Please specify a version along with the MIME type. For example, `Accept: applica
|
|
|
41
41
|
end
|
|
42
42
|
media_type.to_s
|
|
43
43
|
end
|
|
44
|
-
env[
|
|
44
|
+
env["HTTP_ACCEPT"] = media_types.join(", ")
|
|
45
45
|
|
|
46
46
|
version ||= @default
|
|
47
47
|
set_api_version(env, version)
|
data/lib/pliny/request_store.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Pliny
|
|
2
4
|
module RequestStore
|
|
3
5
|
def self.clear!
|
|
@@ -6,12 +8,12 @@ module Pliny
|
|
|
6
8
|
|
|
7
9
|
def self.seed(env)
|
|
8
10
|
store[:request_id] =
|
|
9
|
-
env["REQUEST_IDS"]
|
|
11
|
+
env["REQUEST_IDS"]&.join(",")
|
|
10
12
|
|
|
11
13
|
# a global context that evolves over the lifetime of the request, and is
|
|
12
14
|
# used to tag all log messages that it produces
|
|
13
15
|
store[:log_context] = {
|
|
14
|
-
request_id: store[:request_id]
|
|
16
|
+
request_id: store[:request_id],
|
|
15
17
|
}
|
|
16
18
|
end
|
|
17
19
|
|
data/lib/pliny/rollbar_logger.rb
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Pliny
|
|
2
4
|
class RollbarLogger
|
|
3
5
|
def debug(message)
|
|
4
|
-
log(
|
|
6
|
+
log("debug", message)
|
|
5
7
|
end
|
|
6
8
|
|
|
7
9
|
def info(message)
|
|
8
|
-
log(
|
|
10
|
+
log("info", message)
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def warn(message)
|
|
12
|
-
log(
|
|
14
|
+
log("warn", message)
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def error(message)
|
|
16
|
-
log(
|
|
18
|
+
log("error", message)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def log(level, message)
|
data/lib/pliny/router.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "sinatra/router"
|
|
2
4
|
|
|
3
5
|
module Pliny
|
|
4
6
|
class Router < Sinatra::Router
|
|
5
|
-
|
|
6
7
|
# yield to a builder block in which all defined apps will only respond for
|
|
7
8
|
# the given version
|
|
8
9
|
def version(*versions, &block)
|
data/lib/pliny/tasks/db.rake
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "logger"
|
|
2
4
|
require "uri"
|
|
3
5
|
require "pliny/utils"
|
|
@@ -165,7 +167,7 @@ begin
|
|
|
165
167
|
end
|
|
166
168
|
|
|
167
169
|
def name_from_uri(uri)
|
|
168
|
-
URI.parse(uri).path[1
|
|
170
|
+
URI.parse(uri).path[1..]
|
|
169
171
|
end
|
|
170
172
|
end
|
|
171
173
|
rescue LoadError
|
data/lib/pliny/tasks/schema.rake
CHANGED
data/lib/pliny/tasks.rb
CHANGED
data/lib/pliny/utils.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Pliny
|
|
2
4
|
module Utils
|
|
3
5
|
def self.parse_env(file)
|
|
4
6
|
env = {}
|
|
5
7
|
File.open(file).each do |line|
|
|
6
|
-
line = line.gsub(/#.*$/,
|
|
8
|
+
line = line.gsub(/#.*$/, "").strip
|
|
7
9
|
next if line.empty?
|
|
8
10
|
var, value = line.split("=", 2)
|
|
9
11
|
value.gsub!(/^['"](.*)['"]$/, '\1')
|
|
@@ -27,7 +29,7 @@ module Pliny
|
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
class << self
|
|
30
|
-
|
|
32
|
+
alias_method :require_relative_glob, :require_glob
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
end
|
data/lib/pliny/version.rb
CHANGED
data/lib/pliny.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require:
|
|
2
2
|
- rubocop-rspec
|
|
3
|
-
|
|
4
|
-
TargetRubyVersion: 2.3
|
|
3
|
+
|
|
5
4
|
# Offense count: 8
|
|
6
5
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
|
7
6
|
# URISchemes: http, https
|
|
@@ -24,6 +23,3 @@ Style/Documentation:
|
|
|
24
23
|
Style/StringLiterals:
|
|
25
24
|
Enabled: true
|
|
26
25
|
EnforcedStyle: double_quotes
|
|
27
|
-
|
|
28
|
-
Style/FrozenStringLiteralComment:
|
|
29
|
-
Enabled: false
|
data/lib/template/Gemfile
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
source "https://rubygems.org"
|
|
2
|
-
ruby "
|
|
4
|
+
ruby "3.4.6"
|
|
3
5
|
|
|
4
6
|
gem "pg"
|
|
5
|
-
gem "pliny", "~>
|
|
7
|
+
gem "pliny", "~> 2"
|
|
6
8
|
gem "pry"
|
|
7
|
-
gem "puma", "~>
|
|
9
|
+
gem "puma", "~> 7"
|
|
8
10
|
gem "rack-ssl"
|
|
9
11
|
gem "rack-timeout", "~> 0.6"
|
|
10
12
|
gem "rake"
|
|
11
13
|
gem "rollbar"
|
|
14
|
+
gem "sentry-ruby"
|
|
12
15
|
gem "sequel", "~> 5.73"
|
|
13
16
|
gem "sequel-paranoid"
|
|
14
17
|
gem "sequel_pg", "~> 1.17", require: "sequel"
|
|
15
|
-
gem "sinatra",
|
|
18
|
+
gem "sinatra", "~> 4.0", require: "sinatra/base"
|
|
16
19
|
gem "sinatra-contrib", require: ["sinatra/namespace", "sinatra/reloader"]
|
|
17
20
|
gem "sinatra-router"
|
|
18
21
|
gem "sucker_punch"
|
data/lib/template/Rakefile
CHANGED
data/lib/template/bin/console
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require_relative "../lib/application"
|
|
4
5
|
|
|
@@ -15,7 +16,7 @@ Pry.prompt = [
|
|
|
15
16
|
|
|
16
17
|
proc do |target_self, nest_level, pry|
|
|
17
18
|
basic_prompt(target_self, nest_level, pry) + "* "
|
|
18
|
-
end
|
|
19
|
+
end,
|
|
19
20
|
]
|
|
20
21
|
|
|
21
22
|
Pry.start
|
data/lib/template/bin/run
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "pliny/config_helpers"
|
|
2
4
|
|
|
3
5
|
# Access all config keys like the following:
|
|
@@ -13,23 +15,23 @@ module Config
|
|
|
13
15
|
mandatory :database_url, string
|
|
14
16
|
|
|
15
17
|
# Optional -- value is returned or `nil` if it wasn't present.
|
|
16
|
-
optional :app_name,
|
|
17
|
-
optional :versioning_default,
|
|
18
|
+
optional :app_name, string
|
|
19
|
+
optional :versioning_default, string
|
|
18
20
|
optional :versioning_app_name, string
|
|
19
21
|
|
|
20
22
|
# Override -- value is returned or the set default.
|
|
21
|
-
override :database_timeout, 10,
|
|
22
|
-
override :db_pool,
|
|
23
|
-
override :deployment,
|
|
24
|
-
override :force_ssl,
|
|
25
|
-
override :app_env,
|
|
26
|
-
override :port,
|
|
27
|
-
override :pretty_json,
|
|
28
|
-
override :puma_max_threads, 16,
|
|
29
|
-
override :puma_min_threads, 1,
|
|
30
|
-
override :puma_workers,
|
|
31
|
-
override :raise_errors,
|
|
32
|
-
override :root,
|
|
33
|
-
override :timeout,
|
|
34
|
-
override :versioning,
|
|
23
|
+
override :database_timeout, 10, int
|
|
24
|
+
override :db_pool, 5, int
|
|
25
|
+
override :deployment, "production", string
|
|
26
|
+
override :force_ssl, true, bool
|
|
27
|
+
override :app_env, "production", string
|
|
28
|
+
override :port, 5000, int
|
|
29
|
+
override :pretty_json, false, bool
|
|
30
|
+
override :puma_max_threads, 16, int
|
|
31
|
+
override :puma_min_threads, 1, int
|
|
32
|
+
override :puma_workers, 3, int
|
|
33
|
+
override :raise_errors, false, bool
|
|
34
|
+
override :root, File.expand_path("../../", __FILE__), string
|
|
35
|
+
override :timeout, 10, int
|
|
36
|
+
override :versioning, false, bool
|
|
35
37
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
database_setup_proc = lambda do |conn|
|
|
2
4
|
# identify postgres connections coming from this process in pg_stat_activity
|
|
3
5
|
process_identifier = ENV["DYNO"] || File.basename($PROGRAM_NAME).gsub(/\W+/, "_")
|
|
@@ -6,5 +8,5 @@ database_setup_proc = lambda do |conn|
|
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
DB = Sequel.connect(Config.database_url,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
max_connections: Config.db_pool,
|
|
12
|
+
after_connect: database_setup_proc,)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pliny/error_reporters/sentry"
|
|
4
|
+
|
|
5
|
+
Pliny::ErrorReporters.error_reporters << Pliny::ErrorReporters::Sentry
|
|
6
|
+
|
|
7
|
+
Sentry.init do |config|
|
|
8
|
+
config.dsn = ENV["SENTRY_DSN"]
|
|
9
|
+
config.environment = ENV["SENTRY_ENV"] || ENV["RACK_ENV"]
|
|
10
|
+
config.enabled_environments = ENV["SENTRY_ENABLED_ENVIRONMENTS"]&.split(",") || %w[production staging]
|
|
11
|
+
config.traces_sample_rate = ENV["SENTRY_TRACES_SAMPLE_RATE"]&.to_f || 0.1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Pliny.use Sentry::Rack::CaptureExceptions
|
data/lib/template/config/puma.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "./config/config"
|
|
2
4
|
|
|
3
5
|
environment Config.rack_env
|
|
@@ -6,7 +8,7 @@ quiet
|
|
|
6
8
|
threads Config.puma_min_threads, Config.puma_max_threads
|
|
7
9
|
workers Config.puma_workers
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
before_worker_boot do
|
|
10
12
|
# force Sequel's thread pool to be refreshed
|
|
11
13
|
Sequel::DATABASES.each(&:disconnect)
|
|
12
14
|
end
|
data/lib/template/config.ru
CHANGED
data/lib/template/db/seeds.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Initializer
|
|
2
4
|
def self.run
|
|
3
5
|
require_config
|
|
@@ -11,7 +13,7 @@ module Initializer
|
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def self.require_lib
|
|
14
|
-
require! %w
|
|
16
|
+
require! %w[
|
|
15
17
|
lib/serializers/base
|
|
16
18
|
lib/serializers/**/*
|
|
17
19
|
lib/endpoints/base
|
|
@@ -19,13 +21,13 @@ module Initializer
|
|
|
19
21
|
lib/mediators/base
|
|
20
22
|
lib/mediators/**/*
|
|
21
23
|
lib/routes
|
|
22
|
-
|
|
24
|
+
]
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def self.require_models
|
|
26
|
-
require! %w
|
|
28
|
+
require! %w[
|
|
27
29
|
lib/models/**/*
|
|
28
|
-
|
|
30
|
+
]
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
def self.require_initializers
|
data/lib/template/lib/routes.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
Routes = Rack::Builder.new do
|
|
2
4
|
use Pliny::Middleware::RequestStore::Clear, store: Pliny::RequestStore
|
|
3
5
|
use Pliny::Middleware::CORS
|
|
@@ -6,18 +8,18 @@ Routes = Rack::Builder.new do
|
|
|
6
8
|
use Pliny::Middleware::Metrics
|
|
7
9
|
use Pliny::Middleware::Instruments
|
|
8
10
|
use Pliny::Middleware::CanonicalLogLine,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
emitter: ->(data) {
|
|
12
|
+
Pliny.log_with_default_context({ canonical_log_line: true }.merge(data))
|
|
13
|
+
}
|
|
12
14
|
use Pliny::Middleware::RescueErrors, raise: Config.raise_errors?
|
|
13
15
|
if Config.timeout.positive?
|
|
14
16
|
use Rack::Timeout,
|
|
15
|
-
|
|
17
|
+
service_timeout: Config.timeout
|
|
16
18
|
end
|
|
17
19
|
if Config.versioning?
|
|
18
20
|
use Pliny::Middleware::Versioning,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
default: Config.versioning_default,
|
|
22
|
+
app_name: Config.versioning_app_name
|
|
21
23
|
end
|
|
22
24
|
use Rack::Deflater
|
|
23
25
|
use Rack::MethodOverride
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
|
|
2
3
|
# define our own version of the spec task because rspec might not be available
|
|
3
4
|
# in the production environment, so we can't rely on RSpec::Core::RakeTask
|
|
@@ -6,7 +7,7 @@ task :spec do
|
|
|
6
7
|
require "rspec/core"
|
|
7
8
|
code = RSpec::Core::Runner.run(
|
|
8
9
|
["./spec"],
|
|
9
|
-
$stderr, $stdout
|
|
10
|
+
$stderr, $stdout,
|
|
10
11
|
)
|
|
11
12
|
exit(code) unless code.zero?
|
|
12
13
|
end
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
include Pliny::CanonicalLogLineHelpers
|
|
5
|
+
class TestCanonicalLogLine
|
|
6
|
+
include Pliny::CanonicalLogLineHelpers
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
log_field :field_float, Float
|
|
9
|
+
log_field :field_integer, Integer
|
|
10
|
+
log_field :field_string, String
|
|
11
|
+
end
|
|
11
12
|
|
|
13
|
+
describe Pliny::CanonicalLogLineHelpers do
|
|
12
14
|
it "allows a field to be set" do
|
|
13
15
|
line = TestCanonicalLogLine.new
|
|
14
16
|
line.field_string = "foo"
|
|
@@ -34,6 +36,6 @@ describe Pliny::CanonicalLogLineHelpers do
|
|
|
34
36
|
line.field_integer = 42
|
|
35
37
|
line.field_string = "foo"
|
|
36
38
|
assert_equal({ field_float: 3.14, field_integer: 42, field_string: "foo" },
|
|
37
|
-
line.to_h)
|
|
39
|
+
line.to_h,)
|
|
38
40
|
end
|
|
39
41
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "pliny/commands/creator"
|
|
2
4
|
require "spec_helper"
|
|
3
5
|
|
|
@@ -19,6 +21,7 @@ describe Pliny::Commands::Creator do
|
|
|
19
21
|
@gen.run!
|
|
20
22
|
assert File.exist?("./foobar")
|
|
21
23
|
assert File.exist?("./foobar/Gemfile")
|
|
24
|
+
assert File.exist?("./foobar/.rubocop.yml")
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
it "deletes the .git from it" do
|