2015-08-26 01:42:46 +00:00
|
|
|
module Ci
|
|
|
|
class Trigger < ActiveRecord::Base
|
|
|
|
extend Ci::Model
|
2015-09-10 13:52:52 +00:00
|
|
|
|
2015-08-26 01:42:46 +00:00
|
|
|
acts_as_paranoid
|
|
|
|
|
2015-12-04 11:55:23 +00:00
|
|
|
belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id
|
2015-08-26 01:42:46 +00:00
|
|
|
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
|
|
|
|
|
2016-01-13 11:16:27 +00:00
|
|
|
def last_used
|
|
|
|
last_trigger_request.try(:created_at)
|
|
|
|
end
|
|
|
|
|
2015-08-26 01:42:46 +00:00
|
|
|
def short_token
|
|
|
|
token[0...10]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|