deimos-ruby 1.14.5 → 1.14.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/docs/CONFIGURATION.md +2 -0
- data/lib/deimos/config/configuration.rb +4 -0
- data/lib/deimos/version.rb +1 -1
- data/lib/generators/deimos/schema_class/templates/schema_class.rb.tt +2 -2
- data/lib/generators/deimos/schema_class_generator.rb +8 -0
- data/spec/generators/schema_class_generator_spec.rb +10 -1
- data/spec/snapshots/namespace_folders.snap +1429 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0c3d1a3e60a5e71ea4fd21de8b8f2ed9db064f8ea4f26891169f5e7690ad75c
|
4
|
+
data.tar.gz: afe45152f6834e529d1d9e63b5fd6e2f307d072464224f9e29d8d098d7053ca2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1359ca3c178171f7999edb2dd43385a04a119489bfc4efa4f5811462c23203b88a1ea5661727718a6142dfc725137592166bef5df36d22fc1a4a6a7ff4a6bdc
|
7
|
+
data.tar.gz: 7629b9f1e75dad6ef0862958e448e7b750da434e62d0be754def299919a49f6ac3d0937588bf004c08ef331ea66aba9dcad989906781465c4a4c51c801acca51
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
# 1.14.6 - 2022-06-21
|
11
|
+
|
12
|
+
- Add `generate_namespace_folders` to configuration; this will automatically generate subfolders to the `schemas` folder so that you can have different schemas with the same name but different namespaces generate separate classes.
|
13
|
+
|
10
14
|
# 1.14.5 - 2022-06-21
|
11
15
|
|
12
16
|
- Fix crash with the tracer when error happens in decoding a message during batch consuming
|
data/docs/CONFIGURATION.md
CHANGED
@@ -194,6 +194,8 @@ schema.password|nil|Basic auth password.
|
|
194
194
|
schema.path|nil|Local path to find your schemas.
|
195
195
|
schema.use_schema_classes|false|Set this to true to use generated schema classes in your application.
|
196
196
|
schema.generated_class_path|`app/lib/schema_classes`|Local path to generated schema classes.
|
197
|
+
schema.nest_child_schemas|false|Set to true to nest subschemas within the generated class for the parent schema.
|
198
|
+
schema.generate_namespace_folders|false|Set to true to generate folders for schemas matching the last part of the namespace.
|
197
199
|
|
198
200
|
## Database Producer Configuration
|
199
201
|
|
@@ -347,6 +347,10 @@ module Deimos
|
|
347
347
|
# Set to false to generate child schemas as their own files.
|
348
348
|
# @return [Boolean]
|
349
349
|
setting :nest_child_schemas, true
|
350
|
+
|
351
|
+
# Set to true to generate folders matching the last part of the schema namespace.
|
352
|
+
# @return [Boolean]
|
353
|
+
setting :generate_namespace_folders, false
|
350
354
|
end
|
351
355
|
|
352
356
|
# The configured metrics provider.
|
data/lib/deimos/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is autogenerated by Deimos, Do NOT modify
|
4
|
-
module
|
4
|
+
<%= @modules.map { |m| "module #{m}"}.join('; ') %>
|
5
5
|
### Primary Schema Class ###
|
6
6
|
<%=- @main_class_definition -%>
|
7
7
|
|
8
|
-
end
|
8
|
+
<%= @modules.map { "end" }.join('; ') %>
|
@@ -108,9 +108,17 @@ module Deimos
|
|
108
108
|
# @param key_schema_base [Avro::Schema::NamedSchema, nil]
|
109
109
|
def write_file(schema, key_schema_base)
|
110
110
|
class_template = _generate_class_template_from_schema(schema, key_schema_base)
|
111
|
+
@modules = ['Schemas']
|
112
|
+
namespace_folder = schema.namespace.split('.').last
|
113
|
+
if Deimos.config.schema.generate_namespace_folders
|
114
|
+
@modules.push(namespace_folder.underscore.classify)
|
115
|
+
end
|
111
116
|
@main_class_definition = class_template
|
112
117
|
|
113
118
|
file_prefix = schema.name.underscore.singularize
|
119
|
+
if Deimos.config.schema.generate_namespace_folders
|
120
|
+
file_prefix = "#{namespace_folder}/#{file_prefix}"
|
121
|
+
end
|
114
122
|
filename = "#{Deimos.config.schema.generated_class_path}/#{file_prefix}.rb"
|
115
123
|
template(SCHEMA_CLASS_FILE, filename, force: true)
|
116
124
|
end
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
|
12
12
|
RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
13
13
|
let(:schema_class_path) { 'spec/app/lib/schema_classes' }
|
14
|
-
let(:files) { Dir["#{schema_class_path}
|
14
|
+
let(:files) { Dir["#{schema_class_path}/**/*.rb"].map { |f| [f, File.read(f)]}.to_h }
|
15
15
|
|
16
16
|
before(:each) do
|
17
17
|
Deimos.config.reset!
|
@@ -215,6 +215,15 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
+
context 'with namespace folders' do
|
219
|
+
it 'should generate the correct classes' do
|
220
|
+
Deimos.with_config('schema.generate_namespace_folders' => true) do
|
221
|
+
described_class.start
|
222
|
+
expect(files).to match_snapshot('namespace_folders', snapshot_serializer: MultiFileSerializer)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
218
227
|
context 'nested true' do
|
219
228
|
it 'should generate the correct classes' do
|
220
229
|
Deimos.with_config('schema.nest_child_schemas' => true) do
|