BigW Consortium Gitlab

trigger.rb 660 Bytes
Newer Older
1 2 3
module Ci
  class Trigger < ActiveRecord::Base
    extend Ci::Model
Dmitriy Zaporozhets committed
4

5 6
    acts_as_paranoid

7
    belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    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

23 24 25 26
    def last_used
      last_trigger_request.try(:created_at)
    end

27 28 29 30 31
    def short_token
      token[0...10]
    end
  end
end