BigW Consortium Gitlab

service.rb 1.45 KB
Newer Older
1 2 3 4
# == Schema Information
#
# Table name: services
#
Valery Sizov committed
5 6 7 8 9 10 11 12 13
#  id         :integer          not null, primary key
#  type       :string(255)
#  title      :string(255)
#  project_id :integer          not null
#  created_at :datetime
#  updated_at :datetime
#  active     :boolean          default(FALSE), not null
#  properties :text
#
14

15 16
# To add new service you should build a class inherited from Service
# and implement a set of methods
17
class Service < ActiveRecord::Base
18 19
  serialize :properties, JSON

Dmitriy Zaporozhets committed
20
  default_value_for :active, false
21 22

  after_initialize :initialize_properties
Dmitriy Zaporozhets committed
23

24 25 26 27
  belongs_to :project
  has_one :service_hook

  validates :project_id, presence: true
28 29 30 31

  def activated?
    active
  end
32

33 34 35 36
  def category
    :common
  end

37 38 39 40
  def initialize_properties
    self.properties = {} if properties.nil?
  end

41
  def title
42
    # implement inside child
43 44 45
  end

  def description
46
    # implement inside child
47 48
  end

49 50 51 52
  def help
    # implement inside child
  end

53
  def to_param
54
    # implement inside child
55 56 57
  end

  def fields
58
    # implement inside child
59 60
    []
  end
61 62 63 64

  def execute
    # implement inside child
  end
65 66 67 68

  def can_test?
    !project.empty_repo?
  end
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

  # Provide convenient accessor methods
  # for each serialized property.
  def self.prop_accessor(*args)
    args.each do |arg|
      class_eval %{
        def #{arg}
          properties['#{arg}']
        end

        def #{arg}=(value)
          self.properties['#{arg}'] = value
        end
      }
    end
  end
85
end