Skip to content

Commit

Permalink
Add an Avromatic.eager_load_models attribute reader method (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel authored Oct 28, 2022
1 parent 33a7f73 commit 267335f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# avromatic changelog

## 4.2.0
- Add an `Avromatic.eager_load_models` attribute reader method.
- Remove unnecessary files from the gem distribution.

## 4.1.1
Expand Down
6 changes: 5 additions & 1 deletion lib/avromatic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def self.prepare!
end

def self.eager_load_models=(models)
@eager_load_model_names = Array(models).map { |model| model.is_a?(Class) ? model.name : model }
@eager_load_model_names = Array(models).map { |model| model.is_a?(Class) ? model.name : model }.freeze
end

def self.eager_load_models
@eager_load_model_names
end

def self.eager_load_models!
Expand Down
2 changes: 1 addition & 1 deletion lib/avromatic/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Avromatic
VERSION = '4.1.1'
VERSION = '4.2.0'
end
2 changes: 2 additions & 0 deletions spec/avromatic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@

it "registers models" do
described_class.eager_load_models = ['NestedRecord']
expect(described_class.eager_load_models).to eq(['NestedRecord'])
described_class.prepare!
expect(described_class.nested_models.registered?('test.value')).to be(false)
end

it "registers nested models" do
described_class.eager_load_models = ['NestedNestedRecord']
expect(described_class.eager_load_models).to eq(['NestedNestedRecord'])
described_class.prepare!
expect(described_class.nested_models.registered?('test.__nested_nested_record_sub_record')).to be(true)
expect(described_class.nested_models.registered?('test.__nested_nested_record_sub_subsub_record')).to be(true)
Expand Down

0 comments on commit 267335f

Please sign in to comment.