Sha256: d1e7aa67fb9f68ff5327f1919a6ca2dad844940d403e3777027d8de99f8fb01e
Contents?: true
Size: 1.57 KB
Versions: 6
Compression:
Stored size: 1.57 KB
Contents
module Discerner module Methods module Models module Operator def self.included(base) base.send :include, SoftDelete # Associations base.send :has_many, :search_parameter_values, :inverse_of => :operator base.send :has_many, :search_combinations, :inverse_of => :operator base.send :has_and_belongs_to_many, :parameter_types, :join_table => :discerner_operators_parameter_types # Validations base.send :validates, :symbol, :presence => true, :uniqueness => {:message => "for operator has already been taken"} base.send :validates, :operator_type, :presence => true base.send :validate, :type_supported? # Whitelisting attributes base.send :attr_accessible, :operator_type, :symbol, :text, :deleted_at end # Instance Methods def initialize(*args) super(*args) end def css_class_name css_class = parameter_types.map{ |t| t.name } css_class << operator_type unless operator_type.blank? css_class.join(' ') end private def type_supported? return if self.operator_type.blank? supported_types = ['comparison', 'text_comparison', 'range', 'list', 'presence'] errors.add(:base,"Operator type '#{self.operator_type}' is not supported, please use one of the following types: #{supported_types.join(', ')}") unless supported_types.include?(self.operator_type) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems