diff options
| author | Teddy Wing | 2017-09-19 15:20:01 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-09-19 16:12:55 +0200 |
| commit | 8e8cfa6c52ff8fc2a655b768db5baafed40c1a2d (patch) | |
| tree | dbc7fc1df86820df7950be29945dc9ec4dafad9e | |
| parent | 81b3526cec5384b29752c1816577bf99c69c42c8 (diff) | |
| download | chouette-core-8e8cfa6c52ff8fc2a655b768db5baafed40c1a2d.tar.bz2 | |
Add `ModelAttribute`
This new class will allow us to generate a list of all editable fields
in all our models including the type of each field.
We need this for Compliance Control, in order to get a list of fields or
models & fields that can be selected to validate a given model
validation check. The crucial bits here are the models, fields, and the
types of those fields. These need to be defined (manually at least to
begin with), accessible, and filterable.
Refs #4401
| -rw-r--r-- | lib/model_attribute.rb | 17 | ||||
| -rw-r--r-- | spec/lib/model_attribute_spec.rb | 16 |
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/model_attribute.rb b/lib/model_attribute.rb new file mode 100644 index 000000000..be5caea94 --- /dev/null +++ b/lib/model_attribute.rb @@ -0,0 +1,17 @@ +class ModelAttribute + cattr_reader :all + + @@all = [] + + attr_reader :klass, :name, :data_type + + def self.define(klass, name, data_type) + @@all << new(klass, name, data_type) + end + + def initialize(klass, name, data_type) + @klass = klass + @name = name + @data_type = data_type + end +end diff --git a/spec/lib/model_attribute_spec.rb b/spec/lib/model_attribute_spec.rb new file mode 100644 index 000000000..88d3997b6 --- /dev/null +++ b/spec/lib/model_attribute_spec.rb @@ -0,0 +1,16 @@ +RSpec.describe ModelAttribute do + describe ".define" do + it "adds a new instance of ModelAttribute to @@all" do + ModelAttribute.define(:route, :name, :string) + + expect(ModelAttribute.all.length).to eq(1) + + model_attr = ModelAttribute.all.first + + expect(model_attr).to be_an_instance_of(ModelAttribute) + expect(model_attr.klass).to eq(:route) + expect(model_attr.name).to eq(:name) + expect(model_attr.data_type).to eq(:string) + end + end +end |
