2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
16 class QuoterecordRule < ActiveRecord::Base
17 include Smr::Extensions::DateTimeWrapper
19 belongs_to :User, :foreign_key=>'id_user'
22 validates :id_user, :name, :rule, :related_columns, :date_last_modified, presence: true
23 validates :date_last_modified, numericality: { greater_than: 0 }
24 validate :related_columns_valid
26 # returns :related_columns field as array
27 def get_related_columns
28 if self.related_columns then self.related_columns.split('|')
32 # compact given column names into :related_columns field
33 def set_related_columns(array_of_column_names)
34 self.related_columns = array_of_column_names.uniq.join('|')
40 # custom validator to make sure :related_columns field only talks about
41 # columns a Quoterecord object knows of.
42 def related_columns_valid
43 valid_cols = Quoterecord.get_columns
44 self.get_related_columns.each do |c|
45 if not valid_cols.include?(c) then errors.add(:related_columns, 'a column named "%s" is not accepted by Quoterecord class' % c) end