2018-03-06 13:44:29 +01:00
|
|
|
class ProcedurePath < ApplicationRecord
|
2017-04-14 11:34:53 +02:00
|
|
|
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, presence: true, allow_blank: false, allow_nil: false
|
2016-06-24 16:41:44 +02:00
|
|
|
validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false
|
|
|
|
validates :procedure_id, presence: true, allow_blank: false, allow_nil: false
|
|
|
|
|
2018-05-17 15:31:45 +02:00
|
|
|
belongs_to :test_procedure, class_name: 'Procedure'
|
2016-06-24 16:41:44 +02:00
|
|
|
belongs_to :procedure
|
|
|
|
belongs_to :administrateur
|
2018-05-17 15:32:36 +02:00
|
|
|
|
|
|
|
def self.find_with_procedure(procedure)
|
|
|
|
where(procedure: procedure).or(where(test_procedure: procedure)).last
|
|
|
|
end
|
2018-05-17 15:34:51 +02:00
|
|
|
|
|
|
|
def hide!(procedure)
|
|
|
|
if self.procedure == procedure
|
|
|
|
update(procedure: nil)
|
|
|
|
end
|
|
|
|
if self.test_procedure == procedure
|
|
|
|
update(test_procedure: nil)
|
|
|
|
end
|
|
|
|
if procedure.nil? && test_procedure.nil?
|
|
|
|
destroy
|
|
|
|
end
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|