Module: Request::CustomerResponsibility

Included in:
LibraryCreationRequest, PacBioSamplePrepRequest, PacBioSequencingRequest, Request, LibraryCreation, SequencingRequest
Defined in:
app/models/request/customer_responsibility.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/models/request/customer_responsibility.rb', line 3

def self.included(base)
  base::Metadata.class_eval do
    custom_attribute(:customer_accepts_responsibility, boolean: true)
    validate :customer_can_accept_responsibility?, if: :customer_accepts_responsibility_changed?, on: :update

    def customer_can_accept_responsibility?
      return true unless request.try(:failed?)

      errors.add(:customer_accepts_responsibility, 'can not be changed once a request is failed.')
      raise ActiveRecord::RecordInvalid, self
    end
  end
end