Sha256: a04b043bd711438bc4ed5ab09b173ed340be5a67b592c3e03921a578455f8601

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module Discerner
  module Methods
    module Models
      module ParameterType
        def self.included(base)
          base.send :include, SoftDelete

          # Associations
          base.send :has_many,                :parameters,  inverse_of: :parameter_type
          base.send :has_and_belongs_to_many, :operators,   join_table: :discerner_operators_parameter_types

          # Validations
          base.send :validates, :name, presence: true, uniqueness: {message: "for parameter type has already been taken"}
          base.send :validate,  :name_supported?
        end

        # Instance Methods
        def initialize(*args)
          super(*args)
        end

        def name_supported?
          return if self.name.blank?
          supported_types = ['numeric', 'date', 'list', 'combobox', 'text', 'string', 'search', 'exclusive_list']
          errors.add(:base,"Parameter type '#{self.name}' is not supported, please use one of the following types: #{supported_types.join(', ')}") unless supported_types.include?(self.name)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
discerner-2.0.16 lib/discerner/methods/models/parameter_type.rb
discerner-2.0.15 lib/discerner/methods/models/parameter_type.rb