forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildpack.rb
63 lines (50 loc) · 1.56 KB
/
buildpack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module VCAP::CloudController
class Buildpack < Sequel::Model
plugin :list
export_attributes :name, :stack, :position, :enabled, :locked, :filename
import_attributes :name, :stack, :position, :enabled, :locked, :filename, :key
def self.list_admin_buildpacks(stack_name=nil)
scoped = exclude(key: nil).exclude(key: '')
scoped = scoped.where(stack: stack_name) if stack_name
scoped.order(:position).all
end
def self.at_last_position
where(position: max(:position)).first
end
def self.user_visibility_filter(user)
full_dataset_filter
end
def validate
validates_unique [:name, :stack]
validates_format(/\A(\w|\-)+\z/, :name, message: 'name can only contain alphanumeric characters')
validate_stack_existence
validate_stack_change
end
def locked?
!!locked
end
def enabled?
!!enabled
end
def staging_message
{ buildpack_key: self.key }
end
# This is used in the serialization of apps to JSON. The buildpack object is left in the hash for the app, then the
# JSON encoder calls to_json on the buildpack.
def to_json
MultiJson.dump name
end
def custom?
false
end
private
def validate_stack_change
return if initial_value(:stack).nil?
errors.add(:stack, :buildpack_cant_change_stacks) if column_changes.key?(:stack)
end
def validate_stack_existence
return unless stack
errors.add(:stack, :buildpack_stack_does_not_exist) if Stack.where(name: stack).empty?
end
end
end