@@ -26,8 +26,8 @@ class AppsStillPresentError < StandardError
2626
2727 plugin :serialization
2828
29- export_attributes :name , :description , :build_rootfs_image , :run_rootfs_image
30- import_attributes :name , :description , :build_rootfs_image , :run_rootfs_image
29+ export_attributes :name , :description , :build_rootfs_image , :run_rootfs_image , :deprecated_at , :locked_at , :disabled_at
30+ import_attributes :name , :description , :build_rootfs_image , :run_rootfs_image , :deprecated_at , :locked_at , :disabled_at
3131
3232 strip_attributes :name
3333
@@ -43,6 +43,19 @@ def around_save
4343 def validate
4444 validates_presence :name
4545 validates_unique :name
46+ validate_timestamp_ordering
47+ end
48+
49+ def deprecated?
50+ deprecated_at && deprecated_at <= Time . now
51+ end
52+
53+ def locked?
54+ locked_at && locked_at <= Time . now
55+ end
56+
57+ def disabled?
58+ disabled_at && disabled_at <= Time . now
4659 end
4760
4861 def before_destroy
@@ -95,8 +108,20 @@ def self.populate_from_hash(hash)
95108 stack . set ( hash )
96109 Steno . logger ( 'cc.stack' ) . warn ( 'stack.populate.collision' , hash ) if stack . modified?
97110 else
98- create ( hash . slice ( 'name' , 'description' , 'build_rootfs_image' , 'run_rootfs_image' ) )
111+ create ( hash . slice ( 'name' , 'description' , 'build_rootfs_image' , 'run_rootfs_image' , 'deprecated_at' , 'locked_at' , 'disabled_at' ) )
99112 end
100113 end
114+
115+ private
116+
117+ def validate_timestamp_ordering
118+ return unless [ deprecated_at , locked_at , disabled_at ] . any?
119+
120+ errors . add ( :deprecated_at , 'must be before locked_at' ) if deprecated_at && locked_at && deprecated_at > locked_at
121+
122+ return unless locked_at && disabled_at && locked_at > disabled_at
123+
124+ errors . add ( :locked_at , 'must be before disabled_at' )
125+ end
101126 end
102127end
0 commit comments