aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/model_attribute.rb6
-rw-r--r--spec/lib/model_attribute_spec.rb15
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/model_attribute.rb b/lib/model_attribute.rb
index 84706ba4d..e74dd1060 100644
--- a/lib/model_attribute.rb
+++ b/lib/model_attribute.rb
@@ -15,6 +15,12 @@ class ModelAttribute
end
end
+ def self.methods_by_class_and_type(klass, type)
+ methods_by_class(klass).select do |model_attr|
+ model_attr.data_type == type
+ end
+ end
+
def initialize(klass, name, data_type)
@klass = klass
@name = name
diff --git a/spec/lib/model_attribute_spec.rb b/spec/lib/model_attribute_spec.rb
index 2da178d2c..faea0b483 100644
--- a/spec/lib/model_attribute_spec.rb
+++ b/spec/lib/model_attribute_spec.rb
@@ -31,6 +31,21 @@ RSpec.describe ModelAttribute do
end
end
+ describe ".methods_by_class_and_type" do
+ it "returns ModelAttributes of a certain class and type" do
+ ModelAttribute.instance_variable_set(:@__all__, [
+ ModelAttribute.new(:route, :name, :string),
+ ModelAttribute.new(:route, :checked_at, :date),
+ ModelAttribute.new(:journey_pattern, :name, :string),
+ ModelAttribute.new(:journey_pattern, :section_status, :integer)
+ ])
+
+ expect(ModelAttribute.methods_by_class_and_type(:route, :string)).to match_array([
+ ModelAttribute.new(:route, :name, :string)
+ ])
+ end
+ end
+
describe "#code" do
it "returns a string representation of the attribute" do
model_attr = ModelAttribute.new(:route, :name, :string)