From cc5d68b0397c6a73c809b1617c059b5d8b2eeb2c Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Wed, 26 Apr 2023 17:02:01 -0700 Subject: [PATCH] expose attribute helper names --- lib/support_table_data.rb | 9 +++++++++ spec/support_table_data_spec.rb | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/lib/support_table_data.rb b/lib/support_table_data.rb index edf0814..63445c0 100644 --- a/lib/support_table_data.rb +++ b/lib/support_table_data.rb @@ -79,6 +79,15 @@ def named_instance_attribute_helpers(*attributes) define_support_table_named_instances end + # Get the names of any named instance attribute helpers that have been defined + # with `named_instance_attribute_helpers`. + # + # @return [Array] List of attribute names. + def support_table_attribute_helpers + @support_table_attribute_helpers ||= {} + @support_table_attribute_helpers.keys + end + # Get the data for the support table from the data files. # # @return [Array] List of attributes for all records in the data files. diff --git a/spec/support_table_data_spec.rb b/spec/support_table_data_spec.rb index d2d3ee4..ebec39f 100644 --- a/spec/support_table_data_spec.rb +++ b/spec/support_table_data_spec.rb @@ -148,6 +148,11 @@ expect(Group.secondary_name).to eq "secondary" expect(Group.gray_name).to eq "gray" end + + it "can get a list of the defined attribute helpers" do + expect(Group.support_table_attribute_helpers).to match_array ["group_id", "name"] + expect(Color.support_table_attribute_helpers).to match_array [] + end end describe "protected_instance?" do