BigW Consortium Gitlab

trigger.rb 810 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# == Schema Information
#
# Table name: triggers
#
#  id         :integer          not null, primary key
#  token      :string(255)
#  project_id :integer          not null
#  deleted_at :datetime
#  created_at :datetime
#  updated_at :datetime
#

module Ci
  class Trigger < ActiveRecord::Base
    extend Ci::Model
Dmitriy Zaporozhets committed
16

17 18
    acts_as_paranoid

Dmitriy Zaporozhets committed
19
    belongs_to :project, class_name: 'Ci::Project'
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'

    validates_presence_of :token
    validates_uniqueness_of :token

    before_validation :set_default_values

    def set_default_values
      self.token = SecureRandom.hex(15) if self.token.blank?
    end

    def last_trigger_request
      trigger_requests.last
    end

    def short_token
      token[0...10]
    end
  end
end