debian-mirror-gitlab/app/models/ci/trigger.rb

41 lines
866 B
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
# == Schema Information
#
2015-11-26 14:37:03 +05:30
# Table name: ci_triggers
2015-09-25 12:07:36 +05:30
#
# id :integer not null, primary key
# token :string(255)
# project_id :integer
# deleted_at :datetime
# created_at :datetime
# updated_at :datetime
# gl_project_id :integer
2015-09-25 12:07:36 +05:30
#
module Ci
class Trigger < ActiveRecord::Base
extend Ci::Model
acts_as_paranoid
2015-12-23 02:04:40 +05:30
belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id
2015-09-25 12:07:36 +05:30
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