diff options
| author | Robert | 2017-10-02 08:53:18 +0200 | 
|---|---|---|
| committer | Robert | 2017-10-02 10:52:07 +0200 | 
| commit | 30bdfe7c5557ba85f2c6cb18abe4b0308faa217d (patch) | |
| tree | 2b5c36dced85c09fbfed1bf53a5da827862ee4e6 /app/models | |
| parent | 1bc4ab6684803a3974bd65f6531bd43a57c15fd0 (diff) | |
| download | chouette-core-30bdfe7c5557ba85f2c6cb18abe4b0308faa217d.tar.bz2 | |
Fixes: #4627@0.55h;
        Class Methods replace Class Attributes
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/compliance_control.rb | 31 | ||||
| -rw-r--r-- | app/models/generic_attribute_control/min_max.rb | 11 | ||||
| -rw-r--r-- | app/models/generic_attribute_control/pattern.rb | 9 | ||||
| -rw-r--r-- | app/models/generic_attribute_control/uniqueness.rb | 9 | 
4 files changed, 32 insertions, 28 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 | 
