diff options
| author | Teddy Wing | 2017-09-19 18:13:20 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-09-19 18:13:20 +0200 | 
| commit | a60bf813aa118648998093242d6db0e1d8613e76 (patch) | |
| tree | a75b5ed5275f12515dc2e9ddf1a519c21b34588d /lib | |
| parent | c9a997f337c9b45f62b50629de96fa95f20c1a7f (diff) | |
| download | chouette-core-a60bf813aa118648998093242d6db0e1d8613e76.tar.bz2 | |
ModelAttribute: Add `.methods_by_class` method
Allows us to get all `ModelAttribute`s given a certain class name.
Needed an `#==` method to be able to test object equality more easily so
I added one in.
I don't like that the `klass` is a lowercase symbol and the `klass`
attribute to `.methods_by_class` is a constantized string. Want to
correct that and make them uniform. Only did it this way because that's
how it was suggested in the ticket.
Refs #4401
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/model_attribute.rb | 12 | 
1 files changed, 12 insertions, 0 deletions
| diff --git a/lib/model_attribute.rb b/lib/model_attribute.rb index 98bb54b67..8f1ecabed 100644 --- a/lib/model_attribute.rb +++ b/lib/model_attribute.rb @@ -9,6 +9,12 @@ class ModelAttribute      all << new(klass, name, data_type)    end +  def self.methods_by_class(klass) +    all.select do |model_attr| +      model_attr.klass == klass.downcase.to_sym +    end +  end +    def initialize(klass, name, data_type)      @klass = klass      @name = name @@ -59,4 +65,10 @@ class ModelAttribute    def code      "#{@klass}##{@name}"    end + +  def ==(other) +    klass == other.klass && +      name == other.name && +      data_type == other.data_type +  end  end | 
