foreman/app/models/user_fact.rb @ 5d264a2d
9fd7478e | Paul Kelly | class UserFact < ActiveRecord::Base
|
|
belongs_to :user
|
|||
5d264a2d | Ohad Levy | belongs_to :fact_name
|
|
9fd7478e | Paul Kelly | ||
validates_inclusion_of :andor, :in => %w{and or}
|
|||
validates_inclusion_of :operator, :in => %w{= != > >= < <= }
|
|||
validates_presence_of :fact_name
|
|||
validates_presence_of :criteria
|
|||
validates_presence_of :user
|
|||
def initialize *args
|
|||
super *args
|
|||
operator = "=" if operator.empty?
|
|||
andor = "or" if andor.empty?
|
|||
end
|
|||
def to_s
|
|||
n = user.try(:name) || "Unknown user"
|
|||
fn = fact_name.try(:name) || "Unknown fact"
|
|||
"#{n}:#{fn}:#{criteria.empty? ? "Empty" : criteria}:#{operator}:#{andor}"
|
|||
end
|
|||
end
|