aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-10-02 08:53:18 +0200
committerRobert2017-10-02 10:52:07 +0200
commit30bdfe7c5557ba85f2c6cb18abe4b0308faa217d (patch)
tree2b5c36dced85c09fbfed1bf53a5da827862ee4e6
parent1bc4ab6684803a3974bd65f6531bd43a57c15fd0 (diff)
downloadchouette-core-30bdfe7c5557ba85f2c6cb18abe4b0308faa217d.tar.bz2
Fixes: #4627@0.55h;
Class Methods replace Class Attributes
-rw-r--r--app/models/compliance_control.rb31
-rw-r--r--app/models/generic_attribute_control/min_max.rb11
-rw-r--r--app/models/generic_attribute_control/pattern.rb9
-rw-r--r--app/models/generic_attribute_control/uniqueness.rb9
-rw-r--r--spec/models/generic_attribute_control/min_max_spec.rb4
-rw-r--r--spec/models/generic_attribute_control/pattern_spec.rb4
6 files changed, 36 insertions, 32 deletions
diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb
index 0763de477..930d54fe8 100644
--- a/app/models/compliance_control.rb
+++ b/app/models/compliance_control.rb
@@ -3,10 +3,6 @@ class ComplianceControl < ActiveRecord::Base
belongs_to :compliance_control_set
belongs_to :compliance_control_block
- cattr_reader :default_criticity, :default_code
- @@default_criticity = :warning
- @@default_code = ""
-
enumerize :criticity, in: %i(info warning error), scope: true, default: :info
validates :criticity, presence: true
@@ -15,27 +11,32 @@ class ComplianceControl < ActiveRecord::Base
validates :origin_code, presence: true
validates :compliance_control_set, presence: true
- def self.policy_class
- ComplianceControlPolicy
- end
+ class << self
+ def default_criticity; :warning end
+ def default_code; "" end
+
+ def policy_class
+ ComplianceControlPolicy
+ end
- def self.inherited(child)
- child.instance_eval do
- def model_name
- ComplianceControl.model_name
+ def inherited(child)
+ child.instance_eval do
+ def model_name
+ ComplianceControl.model_name
+ end
end
+ super
end
- super
end
before_validation(on: :create) do
self.name ||= self.class.name
- self.code ||= @@default_code
- self.origin_code ||= @@default_code
+ self.code ||= self.class.default_code
+ self.origin_code ||= self.class.default_code
# TODO: Remove this very ambigous line, as a matter of fact it is never triggered
# **unless** `criticity` is **explicitly** set to nil, thusly bypassing the att's
# initialisation by `Enumerize`'s default.
- self.criticity ||= @@default_criticity
+ self.criticity ||= self.class.default_criticity
end
end
diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb
index d18ff6344..0b0e5a9a7 100644
--- a/app/models/generic_attribute_control/min_max.rb
+++ b/app/models/generic_attribute_control/min_max.rb
@@ -2,17 +2,18 @@ module GenericAttributeControl
class MinMax < ComplianceControl
hstore_accessor :control_attributes, minimum: :integer, maximum: :integer
- cattr_reader :default_criticity, :default_code
- @@default_criticity = :warning
- @@default_code = "3-Generic-2"
validate :min_max_values
def min_max_values
true
end
- def self.dynamic_attributes
- self.hstore_metadata_for_control_attributes.keys
+ class << self
+ def default_criticity; :warning end
+ def default_code; "3-Generic-2" end
+ def dynamic_attributes
+ hstore_metadata_for_control_attributes.keys
+ end
end
end
end
diff --git a/app/models/generic_attribute_control/pattern.rb b/app/models/generic_attribute_control/pattern.rb
index 9e5a311de..72bb1770a 100644
--- a/app/models/generic_attribute_control/pattern.rb
+++ b/app/models/generic_attribute_control/pattern.rb
@@ -2,13 +2,14 @@ module GenericAttributeControl
class Pattern < ComplianceControl
hstore_accessor :control_attributes, value: :string, pattern: :string
- cattr_reader :default_criticity, :default_code
- @@default_criticity = :warning
- @@default_code = "3-Generic-3"
-
validate :pattern_match
def pattern_match
true
end
+
+ class << self
+ def default_criticity; :warning end
+ def default_code; "3-Generic-3" end
+ end
end
end
diff --git a/app/models/generic_attribute_control/uniqueness.rb b/app/models/generic_attribute_control/uniqueness.rb
index 3efe1deac..6ffe78565 100644
--- a/app/models/generic_attribute_control/uniqueness.rb
+++ b/app/models/generic_attribute_control/uniqueness.rb
@@ -2,13 +2,14 @@ module GenericAttributeControl
class Uniqueness < ComplianceControl
hstore_accessor :control_attributes, name: :string
- cattr_reader :default_criticity, :default_code
- @@default_criticity = :warning
- @@default_code = "3-Generic-3"
-
validate :unique_values
def unique_values
true
end
+
+ class << self
+ def default_criticity; :warning end
+ def default_code; "3-Generic-3" end
+ end
end
end
diff --git a/spec/models/generic_attribute_control/min_max_spec.rb b/spec/models/generic_attribute_control/min_max_spec.rb
index b38032965..d7e1d9a53 100644
--- a/spec/models/generic_attribute_control/min_max_spec.rb
+++ b/spec/models/generic_attribute_control/min_max_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe GenericAttributeControl::MinMax, type: :model do
end
end
context 'are used in instantiation' do
- let( :record ){ create :uniqueness }
+ let( :record ){ create :min_max }
let( :default_att_names ){%w[ code origin_code criticity ]}
it 'all defaults' do
@@ -43,7 +43,7 @@ RSpec.describe GenericAttributeControl::MinMax, type: :model do
expected_values = expected.values_at(*default_att_names)
# Remove key to be tested from atts passed to `#create`
construction_atts = H.first_values(atts).merge(key => nil).compact
- explicit = create :uniqueness, construction_atts
+ explicit = create :min_max, construction_atts
expect( explicit.attributes.values_at(*default_att_names ))
.to eq(expected_values)
diff --git a/spec/models/generic_attribute_control/pattern_spec.rb b/spec/models/generic_attribute_control/pattern_spec.rb
index 646bb735e..294d33c4a 100644
--- a/spec/models/generic_attribute_control/pattern_spec.rb
+++ b/spec/models/generic_attribute_control/pattern_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe GenericAttributeControl::Pattern, type: :model do
end
end
context 'are used in instantiation' do
- let( :record ){ create :uniqueness }
+ let( :record ){ create :pattern }
let( :default_att_names ){%w[ code origin_code criticity ]}
it 'all defaults' do
@@ -43,7 +43,7 @@ RSpec.describe GenericAttributeControl::Pattern, type: :model do
expected_values = expected.values_at(*default_att_names)
# Remove key to be tested from atts passed to `#create`
construction_atts = H.first_values(atts).merge(key => nil).compact
- explicit = create :uniqueness, construction_atts
+ explicit = create :pattern, construction_atts
expect( explicit.attributes.values_at(*default_att_names ))
.to eq(expected_values)