From 267335f4367e44aa4e64cfc646e789ce646be756 Mon Sep 17 00:00:00 2001 From: Joel Turkel Date: Fri, 28 Oct 2022 12:46:26 -0400 Subject: [PATCH] Add an Avromatic.eager_load_models attribute reader method (#147) --- CHANGELOG.md | 1 + lib/avromatic.rb | 6 +++++- lib/avromatic/version.rb | 2 +- spec/avromatic_spec.rb | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e93ecb..6d29f7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/avromatic.rb b/lib/avromatic.rb index b2c2730..b129260 100644 --- a/lib/avromatic.rb +++ b/lib/avromatic.rb @@ -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! diff --git a/lib/avromatic/version.rb b/lib/avromatic/version.rb index df6ee8c..6b626c4 100644 --- a/lib/avromatic/version.rb +++ b/lib/avromatic/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Avromatic - VERSION = '4.1.1' + VERSION = '4.2.0' end diff --git a/spec/avromatic_spec.rb b/spec/avromatic_spec.rb index 1948dc0..43a8679 100644 --- a/spec/avromatic_spec.rb +++ b/spec/avromatic_spec.rb @@ -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)