1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/relation_transition.rb

38 lines
787 B
Ruby
Raw Normal View History

2019-09-21 12:46:20 -04:00
# frozen_string_literal: true
class RelationTransition < ApplicationRecord
FORMAT_RE = /\A[^[:space:]]+(.*[^[:space:]]+)?\z/.freeze
################
# Associations #
################
belongs_to :from_status,
class_name: 'RelationStatus',
2019-09-21 13:13:14 -04:00
inverse_of: :transitions,
2019-09-21 12:46:20 -04:00
optional: true
belongs_to :to_status,
class_name: 'RelationStatus'
###############
# Validations #
###############
validates :name,
presence: true,
length: { in: 1..255 },
format: FORMAT_RE,
uniqueness: true
validate :statuses_are_not_equal
private
def statuses_are_not_equal
return if from_status.nil? || to_status.nil? || from_status != to_status
errors.add :to_status
end
end