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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b9a66f3564707054fd14e3115be4013984bbe64533b8fd2d01b8c2a660a2a65
|
|
4
|
+
data.tar.gz: 328be753f507e23186ee796c86dfb32e642a9144010c4f8d1c88647dc46bc2bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b792d492c87c023d48d65e467559d7c6dfda6b942a47d7f890196f6b791439c6e309c7cab3c920c2d8b81bca398cf77eb307dc4c189f027672a94f451cd344c
|
|
7
|
+
data.tar.gz: 762f3d62946c779204ce34712b95aced9a2246fe330baf536561ddf9a5411b6d6048a01fadff45c793b4cb33e2340400052fc21a7af7b0ca8329c74ac8867351
|
data/bin/pliny-generate
CHANGED
data/bin/pliny-new
CHANGED
data/bin/pliny-update
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "pathname"
|
|
5
|
+
require "pliny/version"
|
|
6
|
+
require "uri"
|
|
7
|
+
require "erb"
|
|
8
|
+
require "ostruct"
|
|
7
9
|
|
|
8
10
|
module Pliny::Commands
|
|
9
11
|
class Creator
|
|
@@ -24,8 +26,9 @@ module Pliny::Commands
|
|
|
24
26
|
|
|
25
27
|
FileUtils.copy_entry template_dir, app_dir
|
|
26
28
|
FileUtils.rm_rf("#{app_dir}/.git")
|
|
29
|
+
FileUtils.mv("#{app_dir}/.rubocop_template.yml", "#{app_dir}/.rubocop.yml")
|
|
27
30
|
parse_erb_files
|
|
28
|
-
display
|
|
31
|
+
display "Pliny app created. To start, run:"
|
|
29
32
|
display "cd #{app_dir} && bin/setup"
|
|
30
33
|
end
|
|
31
34
|
|
|
@@ -33,15 +36,13 @@ module Pliny::Commands
|
|
|
33
36
|
|
|
34
37
|
def parse_erb_files
|
|
35
38
|
Dir.glob("#{app_dir}/{*,.*}.erb").each do |file|
|
|
36
|
-
static_file = file.gsub(/\.erb$/,
|
|
39
|
+
static_file = file.gsub(/\.erb$/, "")
|
|
37
40
|
|
|
38
41
|
template = ERB.new(File.read(file))
|
|
39
42
|
context = OpenStruct.new(app_name: name)
|
|
40
43
|
content = template.result(context.instance_eval { binding })
|
|
41
44
|
|
|
42
|
-
File.
|
|
43
|
-
f.write content
|
|
44
|
-
end
|
|
45
|
+
File.write(static_file, content)
|
|
45
46
|
FileUtils.rm(file)
|
|
46
47
|
end
|
|
47
48
|
end
|
|
@@ -55,7 +56,7 @@ module Pliny::Commands
|
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
def template_dir
|
|
58
|
-
File.expand_path(
|
|
59
|
+
File.expand_path("../../template", File.dirname(__FILE__))
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
def app_dir
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/inflector"
|
|
4
|
+
require "ostruct"
|
|
5
|
+
require "erb"
|
|
6
|
+
require "fileutils"
|
|
7
|
+
require "pliny"
|
|
6
8
|
|
|
7
9
|
module Pliny::Commands
|
|
8
10
|
class Generator
|
|
@@ -32,7 +34,7 @@ module Pliny::Commands
|
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
def table_name
|
|
35
|
-
name.tableize.tr(
|
|
37
|
+
name.tableize.tr("/", "_")
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def display(msg)
|
|
@@ -41,7 +43,7 @@ module Pliny::Commands
|
|
|
41
43
|
|
|
42
44
|
def render_template(template_file, vars = {})
|
|
43
45
|
template_path = File.dirname(__FILE__) + "/../../templates/#{template_file}"
|
|
44
|
-
template = ERB.new(File.read(template_path), trim_mode:
|
|
46
|
+
template = ERB.new(File.read(template_path), trim_mode: ">")
|
|
45
47
|
context = OpenStruct.new(vars)
|
|
46
48
|
template.result(context.instance_eval { binding })
|
|
47
49
|
end
|
|
@@ -54,7 +56,7 @@ module Pliny::Commands
|
|
|
54
56
|
|
|
55
57
|
def write_file(destination_path)
|
|
56
58
|
FileUtils.mkdir_p(File.dirname(destination_path))
|
|
57
|
-
File.open(destination_path,
|
|
59
|
+
File.open(destination_path, "w") do |f|
|
|
58
60
|
f.puts yield
|
|
59
61
|
end
|
|
60
62
|
end
|
|
@@ -62,7 +64,7 @@ module Pliny::Commands
|
|
|
62
64
|
private
|
|
63
65
|
|
|
64
66
|
def normalize_name(name)
|
|
65
|
-
name.underscore.tr(
|
|
67
|
+
name.underscore.tr(" ", "_")
|
|
66
68
|
end
|
|
67
69
|
end
|
|
68
70
|
end
|
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
2
4
|
|
|
3
5
|
module Pliny::Commands
|
|
4
6
|
class Generator
|
|
5
7
|
class Endpoint < Base
|
|
6
8
|
def create
|
|
7
9
|
endpoint = "./lib/endpoints/#{pluralized_file_name}.rb"
|
|
8
|
-
template = options[:scaffold] ?
|
|
10
|
+
template = options[:scaffold] ? "endpoint_scaffold.erb" : "endpoint.erb"
|
|
9
11
|
write_template(template, endpoint,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
plural_class_name: plural_class_name,
|
|
13
|
+
singular_class_name: singular_class_name,
|
|
14
|
+
field_name: field_name,
|
|
15
|
+
url_path: url_path,)
|
|
14
16
|
display "created endpoint file #{endpoint}"
|
|
15
|
-
display
|
|
17
|
+
display "add the following to lib/routes.rb:"
|
|
16
18
|
display " mount Endpoints::#{plural_class_name}"
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def create_test
|
|
20
22
|
test = "./spec/endpoints/#{pluralized_file_name}_spec.rb"
|
|
21
|
-
write_template(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
write_template("endpoint_test.erb", test,
|
|
24
|
+
plural_class_name: plural_class_name,
|
|
25
|
+
singular_class_name: singular_class_name,
|
|
26
|
+
url_path: url_path,)
|
|
25
27
|
display "created test #{test}"
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def create_acceptance_test
|
|
29
31
|
test = "./spec/acceptance/#{pluralized_file_name}_spec.rb"
|
|
30
|
-
template = options[:scaffold] ?
|
|
32
|
+
template = options[:scaffold] ? "endpoint_scaffold_acceptance_test.erb" : "endpoint_acceptance_test.erb"
|
|
31
33
|
write_template(template, test,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
plural_class_name: plural_class_name,
|
|
35
|
+
field_name: field_name,
|
|
36
|
+
singular_class_name: singular_class_name,
|
|
37
|
+
url_path: url_path,)
|
|
36
38
|
display "created test #{test}"
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def url_path
|
|
40
|
-
|
|
42
|
+
"/" + name.pluralize.tr("_", "-")
|
|
41
43
|
end
|
|
42
44
|
end
|
|
43
45
|
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
2
4
|
|
|
3
5
|
module Pliny::Commands
|
|
4
6
|
class Generator
|
|
5
7
|
class Mediator < Base
|
|
6
8
|
def create
|
|
7
9
|
mediator = "./lib/mediators/#{field_name}.rb"
|
|
8
|
-
write_template(
|
|
9
|
-
|
|
10
|
+
write_template("mediator.erb", mediator,
|
|
11
|
+
singular_class_name: singular_class_name,)
|
|
10
12
|
display "created mediator file #{mediator}"
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def create_test
|
|
14
16
|
test = "./spec/mediators/#{field_name}_spec.rb"
|
|
15
|
-
write_template(
|
|
16
|
-
|
|
17
|
+
write_template("mediator_test.erb", test,
|
|
18
|
+
singular_class_name: singular_class_name,)
|
|
17
19
|
display "created test #{test}"
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
2
4
|
|
|
3
5
|
module Pliny::Commands
|
|
4
6
|
class Generator
|
|
5
7
|
class Migration < Base
|
|
6
8
|
def create
|
|
7
9
|
migration = "./db/migrate/#{Time.now.to_i}_#{name}.rb"
|
|
8
|
-
write_template(
|
|
10
|
+
write_template("migration.erb", migration)
|
|
9
11
|
display "created migration #{migration}"
|
|
10
12
|
end
|
|
11
13
|
end
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
2
4
|
|
|
3
5
|
module Pliny::Commands
|
|
4
6
|
class Generator
|
|
5
7
|
class Model < Base
|
|
6
8
|
def create
|
|
7
9
|
model = "./lib/models/#{field_name}.rb"
|
|
8
|
-
write_template(
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
write_template("model.erb", model,
|
|
11
|
+
singular_class_name: singular_class_name,
|
|
12
|
+
paranoid: options[:paranoid],)
|
|
11
13
|
display "created model file #{model}"
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def create_migration
|
|
15
17
|
migration = "./db/migrate/#{Time.now.to_i}_create_#{table_name}.rb"
|
|
16
|
-
write_template(
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
write_template("model_migration.erb", migration,
|
|
19
|
+
table_name: table_name,
|
|
20
|
+
paranoid: options[:paranoid],)
|
|
19
21
|
display "created migration #{migration}"
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def create_test
|
|
23
25
|
test = "./spec/models/#{field_name}_spec.rb"
|
|
24
|
-
write_template(
|
|
25
|
-
|
|
26
|
+
write_template("model_test.erb", test,
|
|
27
|
+
singular_class_name: singular_class_name,)
|
|
26
28
|
display "created test #{test}"
|
|
27
29
|
end
|
|
28
30
|
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
2
4
|
|
|
3
5
|
module Pliny::Commands
|
|
4
6
|
class Generator
|
|
5
7
|
class Serializer < Base
|
|
6
8
|
def create
|
|
7
9
|
serializer = "./lib/serializers/#{field_name}.rb"
|
|
8
|
-
write_template(
|
|
9
|
-
|
|
10
|
+
write_template("serializer.erb", serializer,
|
|
11
|
+
singular_class_name: singular_class_name,)
|
|
10
12
|
display "created serializer file #{serializer}"
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def create_test
|
|
14
16
|
test = "./spec/serializers/#{field_name}_spec.rb"
|
|
15
|
-
write_template(
|
|
16
|
-
|
|
17
|
+
write_template("serializer_test.erb", test,
|
|
18
|
+
singular_class_name: singular_class_name,)
|
|
17
19
|
display "created test #{test}"
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pliny/version"
|
|
4
|
+
require "thor"
|
|
3
5
|
|
|
4
6
|
module Pliny::Commands
|
|
5
7
|
class Generator < Thor
|
|
6
|
-
desc
|
|
8
|
+
desc "endpoint NAME", "Generates an endpoint"
|
|
7
9
|
method_option :scaffold, type: :boolean, default: false, hide: true
|
|
8
10
|
def endpoint(name)
|
|
9
|
-
require_relative
|
|
11
|
+
require_relative "generator/endpoint"
|
|
10
12
|
|
|
11
13
|
ep = Endpoint.new(name, options)
|
|
12
14
|
ep.create
|
|
@@ -14,27 +16,27 @@ module Pliny::Commands
|
|
|
14
16
|
ep.create_acceptance_test
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
desc
|
|
19
|
+
desc "mediator NAME", "Generates a mediator"
|
|
18
20
|
def mediator(name)
|
|
19
|
-
require_relative
|
|
21
|
+
require_relative "generator/mediator"
|
|
20
22
|
|
|
21
23
|
md = Mediator.new(name, options)
|
|
22
24
|
md.create
|
|
23
25
|
md.create_test
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
desc
|
|
28
|
+
desc "migration NAME", "Generates a migration"
|
|
27
29
|
def migration(name)
|
|
28
|
-
require_relative
|
|
30
|
+
require_relative "generator/migration"
|
|
29
31
|
|
|
30
32
|
mg = Migration.new(name, options)
|
|
31
33
|
mg.create
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
desc
|
|
35
|
-
method_option :paranoid, type: :boolean, default: false, desc:
|
|
36
|
+
desc "model NAME", "Generates a model"
|
|
37
|
+
method_option :paranoid, type: :boolean, default: false, desc: "adds paranoid support to model"
|
|
36
38
|
def model(name)
|
|
37
|
-
require_relative
|
|
39
|
+
require_relative "generator/model"
|
|
38
40
|
|
|
39
41
|
md = Model.new(name, options)
|
|
40
42
|
md.create
|
|
@@ -42,8 +44,8 @@ module Pliny::Commands
|
|
|
42
44
|
md.create_test
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
desc
|
|
46
|
-
method_option :paranoid, type: :boolean, default: false, desc:
|
|
47
|
+
desc "scaffold NAME", "Generates a scaffold of endpoint, model, schema and serializer"
|
|
48
|
+
method_option :paranoid, type: :boolean, default: false, desc: "adds paranoid support to model"
|
|
47
49
|
method_option :scaffold, type: :boolean, default: true, hide: true
|
|
48
50
|
def scaffold(name)
|
|
49
51
|
endpoint(name)
|
|
@@ -52,18 +54,18 @@ module Pliny::Commands
|
|
|
52
54
|
serializer(name)
|
|
53
55
|
end
|
|
54
56
|
|
|
55
|
-
desc
|
|
57
|
+
desc "schema NAME", "Generates a schema"
|
|
56
58
|
def schema(name)
|
|
57
|
-
require_relative
|
|
59
|
+
require_relative "generator/schema"
|
|
58
60
|
|
|
59
61
|
sc = Schema.new(name, options)
|
|
60
62
|
sc.create
|
|
61
63
|
sc.rebuild
|
|
62
64
|
end
|
|
63
65
|
|
|
64
|
-
desc
|
|
66
|
+
desc "serializer NAME", "Generates a serializer"
|
|
65
67
|
def serializer(name)
|
|
66
|
-
require_relative
|
|
68
|
+
require_relative "generator/serializer"
|
|
67
69
|
|
|
68
70
|
se = Serializer.new(name, options)
|
|
69
71
|
se.create
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "fileutils"
|
|
2
4
|
require "pathname"
|
|
3
5
|
require "pliny/version"
|
|
@@ -21,7 +23,7 @@ module Pliny::Commands
|
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
version_current = get_current_version
|
|
24
|
-
version_target
|
|
26
|
+
version_target = Gem::Version.new(Pliny::VERSION)
|
|
25
27
|
|
|
26
28
|
if version_current == version_target
|
|
27
29
|
display "Version #{version_current} is current, nothing to update."
|
|
@@ -50,14 +52,14 @@ module Pliny::Commands
|
|
|
50
52
|
|
|
51
53
|
def get_current_version
|
|
52
54
|
File.read("./Gemfile.lock").split("\n").each do |line|
|
|
53
|
-
next unless pliny_version = line.match(/pliny \(([\d
|
|
55
|
+
next unless (pliny_version = line.match(/pliny \(([\d+.]+)\)/))
|
|
54
56
|
return Gem::Version.new(pliny_version[1])
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
def save_patch(curr, target)
|
|
59
61
|
# take a diff of changes that happened to the template app in Pliny
|
|
60
|
-
diff = `cd #{repo_dir} && git diff v#{curr}..v#{target} lib/template/`
|
|
62
|
+
diff = `cd #{repo_dir} && GIT_CONFIG_GLOBAL=/dev/null git diff v#{curr}..v#{target} lib/template/`
|
|
61
63
|
|
|
62
64
|
# remove /lib/template from the path of files in the patch so that we can
|
|
63
65
|
# apply these to the current folder
|
data/lib/pliny/config_helpers.rb
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Pliny
|
|
2
4
|
module CastingConfigHelpers
|
|
3
|
-
def mandatory(name, method=nil)
|
|
5
|
+
def mandatory(name, method = nil)
|
|
4
6
|
value = cast(ENV.fetch(name.to_s.upcase), method)
|
|
5
7
|
create(name, value)
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
def optional(name, method=nil)
|
|
10
|
+
def optional(name, method = nil)
|
|
9
11
|
value = cast(ENV[name.to_s.upcase], method)
|
|
10
12
|
create(name, value)
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
def override(name, default, method=nil)
|
|
15
|
+
def override(name, default, method = nil)
|
|
14
16
|
value = cast(ENV.fetch(name.to_s.upcase, default), method)
|
|
15
17
|
create(name, value)
|
|
16
18
|
end
|
|
@@ -24,7 +26,7 @@ module Pliny
|
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
def bool
|
|
27
|
-
->(v) { v.to_s==
|
|
29
|
+
->(v) { v.to_s == "true" }
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
def string
|
|
@@ -42,31 +44,19 @@ module Pliny
|
|
|
42
44
|
# optional :notype, array
|
|
43
45
|
# => ['a', 'b']
|
|
44
46
|
def array(method = nil)
|
|
45
|
-
->
|
|
46
|
-
|
|
47
|
-
v.split(",").map{|a| cast(a, method) }
|
|
48
|
-
end
|
|
47
|
+
->(v) do
|
|
48
|
+
v&.split(",")&.map { |a| cast(a, method) }
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def rack_env
|
|
53
|
-
if
|
|
53
|
+
if app_env == "development" || app_env == "test"
|
|
54
54
|
"development"
|
|
55
55
|
else
|
|
56
56
|
"deployment"
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
# DEPRECATED: pliny_env is deprecated in favour of app_env.
|
|
61
|
-
# See more at https://github.com/interagent/pliny/issues/277
|
|
62
|
-
#
|
|
63
|
-
# This method is kept temporary in case it is used somewhere in the app.
|
|
64
|
-
def pliny_env
|
|
65
|
-
warn "Config.pliny_env is deprecated and will be removed, " \
|
|
66
|
-
"use Config.app_env instead."
|
|
67
|
-
env
|
|
68
|
-
end
|
|
69
|
-
|
|
70
60
|
private
|
|
71
61
|
|
|
72
62
|
def cast(value, method)
|
|
@@ -76,24 +66,10 @@ module Pliny
|
|
|
76
66
|
def create(name, value)
|
|
77
67
|
instance_variable_set(:"@#{name}", value)
|
|
78
68
|
instance_eval "def #{name}; @#{name} end", __FILE__, __LINE__
|
|
79
|
-
if value.
|
|
69
|
+
if value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.is_a?(NilClass)
|
|
80
70
|
instance_eval "def #{name}?; !!@#{name} end", __FILE__, __LINE__
|
|
81
71
|
end
|
|
82
72
|
end
|
|
83
|
-
|
|
84
|
-
# This method helps with transition from PLINY_ENV to APP_ENV.
|
|
85
|
-
def env
|
|
86
|
-
legacy_env || app_env
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# PLINY_ENV is deprecated, but it might be still used by someone.
|
|
90
|
-
def legacy_env
|
|
91
|
-
if ENV.key?('PLINY_ENV')
|
|
92
|
-
warn "PLINY_ENV is deprecated in favour of APP_ENV, " \
|
|
93
|
-
"update .env file or application configuration."
|
|
94
|
-
ENV['PLINY_ENV']
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
73
|
end
|
|
98
74
|
|
|
99
75
|
# DEPRECATED: ConfigHelpers was a slightly more primitive version
|
|
@@ -130,7 +106,6 @@ module Pliny
|
|
|
130
106
|
end
|
|
131
107
|
end
|
|
132
108
|
end
|
|
133
|
-
|
|
134
109
|
end
|
|
135
110
|
|
|
136
111
|
# Supress the "use RbConfig instead" warning
|