deimos-ruby 1.14.5 → 1.14.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 872f449652ea05dfe9aabf1b144391b98d63fa03b193c7160931748b514ff534
4
- data.tar.gz: cf6e3b54b909d1731a06d68fbfa1f7dbad5d78ce4e7de01bf712161061515ceb
3
+ metadata.gz: a0c3d1a3e60a5e71ea4fd21de8b8f2ed9db064f8ea4f26891169f5e7690ad75c
4
+ data.tar.gz: afe45152f6834e529d1d9e63b5fd6e2f307d072464224f9e29d8d098d7053ca2
5
5
  SHA512:
6
- metadata.gz: e2737082fbada9724a9e94615308e4f7cdb17a36b8202dd1bf1f83c46e6378f5a6724eeb9e4cae5b86beabff94246ae90619b4b8e55f06064adf8dcd42e2ef14
7
- data.tar.gz: 70b73b45dcb4b881bfa2c50aae105af62caf2d4aad2b103a807c1d776477c49621650434ae5aba9358b7cb1f977fe246e831f655bc7bfde902417bcf9a0b9ce5
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
@@ -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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.14.5'
4
+ VERSION = '1.14.6'
5
5
  end
@@ -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 Schemas
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}/*.rb"].map { |f| [f, File.read(f)]}.to_h }
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