Sha256: 981990d5755adfccb51b09113ebacb79791d4d955ed63a8df22f00790db00a62

Contents?: true

Size: 1.3 KB

Versions: 23

Compression:

Stored size: 1.3 KB

Contents

module Naf
  class LoggerStyle < NafBase
    # Protect from mass-assignment issue
    attr_accessible :name,
                    :note,
                    :logger_style_names_attributes

    #---------------------
    # *** Associations ***
    #+++++++++++++++++++++

    has_many :logger_style_names,
      class_name: '::Naf::LoggerStyleName'
    has_many :logger_names,
      through: :logger_style_names

    accepts_nested_attributes_for :logger_style_names

    #--------------------
    # *** Validations ***
    #++++++++++++++++++++

    validates :name, uniqueness: true,
                     presence: true
    validate :check_logger_style_names_attributes

    before_save :check_blank_values

    #-------------------------
    # *** Instance Methods ***
    #+++++++++++++++++++++++++

    def _logger_names
      logger_style_names.map do |lsn|
        lsn.logger_name.name
      end.join(', ')
    end

    def logger_levels
      logger_style_names.map do |lsn|
        lsn.logger_level.level
      end.join(', ')
    end

    def check_logger_style_names_attributes
      if logger_style_names.map{ |ln| ln.logger_name_id }.uniq!
        errors.add(:logger_name_id, "should be an uniqueness")
      end
    end

    private

    def check_blank_values
      self.note = nil if self.note.blank?
    end

  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
naf-2.1.13 app/models/naf/logger_style.rb
naf-2.1.12 app/models/naf/logger_style.rb
naf-2.1.11 app/models/naf/logger_style.rb
naf-2.1.10 app/models/naf/logger_style.rb
naf-2.1.9 app/models/naf/logger_style.rb
naf-2.1.8 app/models/naf/logger_style.rb
naf-2.1.6 app/models/naf/logger_style.rb
naf-2.1.5 app/models/naf/logger_style.rb
naf-2.1.4 app/models/naf/logger_style.rb
naf-2.1.3 app/models/naf/logger_style.rb
naf-2.1.2 app/models/naf/logger_style.rb
naf-2.1.1 app/models/naf/logger_style.rb
naf-2.1.0 app/models/naf/logger_style.rb
naf-2.0.4 app/models/naf/logger_style.rb
naf-2.0.3 app/models/naf/logger_style.rb
naf-2.0.2 app/models/naf/logger_style.rb
naf-2.0.1 app/models/naf/logger_style.rb
naf-2.0.0 app/models/naf/logger_style.rb
naf-1.1.4 app/models/naf/logger_style.rb
naf-1.1.3 app/models/naf/logger_style.rb