Skip to content

Commit 9fd28cc

Browse files
c0d1ngm0nk3ynicolasbender
authored andcommitted
WIP: Restructured buildpack model
Co-authored-by: Nicolas Bender <[email protected]>
1 parent a364da4 commit 9fd28cc

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

app/models/runtime/buildpack.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
module VCAP::CloudController
22
class Buildpack < Sequel::Model
33
plugin :list
4+
plugin :single_table_inheritance, :lifecycle,
5+
model_map: {
6+
VCAP::CloudController::Lifecycles::BUILDPACK => "VCAP::CloudController::ClassicBuildpack",
7+
VCAP::CloudController::Lifecycles::CNB => "VCAP::CloudController::CNBBuildpack"
8+
}
49

510
export_attributes :name, :stack, :position, :enabled, :locked, :filename
611
import_attributes :name, :stack, :position, :enabled, :locked, :filename, :key
@@ -16,21 +21,6 @@ class Buildpack < Sequel::Model
1621
add_association_dependencies labels: :destroy
1722
add_association_dependencies annotations: :destroy
1823

19-
def self.list_admin_buildpacks(stack_name=nil)
20-
scoped = exclude(key: nil).exclude(key: '')
21-
if stack_name.present?
22-
scoped = scoped.filter(Sequel.or([
23-
[:stack, stack_name],
24-
[:stack, nil]
25-
]))
26-
end
27-
scoped.order(:position).all
28-
end
29-
30-
def self.at_last_position
31-
where(position: max(:position)).first
32-
end
33-
3424
def self.user_visibility_filter(_user)
3525
full_dataset_filter
3626
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module VCAP::CloudController
2+
class ClassicBuildpack < Buildpack
3+
4+
def self.list_admin_buildpacks(stack_name=nil)
5+
scoped = exclude(key: nil).exclude(key: '')
6+
if stack_name.present?
7+
scoped = scoped.filter(Sequel.or([
8+
[:stack, stack_name],
9+
[:stack, nil]
10+
]))
11+
end
12+
scoped.order(:position).all
13+
end
14+
15+
def self.at_last_position
16+
where(position: max(:position)).first
17+
end
18+
19+
end
20+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module VCAP::CloudController
2+
class CNBBuildpack < Buildpack
3+
4+
def self.list_admin_buildpacks(stack_name=nil)
5+
scoped = exclude(key: nil).exclude(key: '')
6+
if stack_name.present?
7+
scoped = scoped.filter(Sequel.or([
8+
[:stack, stack_name],
9+
[:stack, nil]
10+
]))
11+
end
12+
scoped.order(:position).all
13+
end
14+
15+
def self.at_last_position
16+
where(position: max(:position)).first
17+
end
18+
19+
end
20+
end

0 commit comments

Comments
 (0)