Class: Flapjack::Data::ScheduledMaintenance
- Inherits:
-
Object
- Object
- Flapjack::Data::ScheduledMaintenance
- Includes:
- ActiveModel::Serializers::JSON, Extensions::Associations, Extensions::ShortName, Swagger::Blocks, Zermelo::Records::RedisSortedSet
- Defined in:
- lib/flapjack/data/scheduled_maintenance.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#duration ⇒ Object
# FIXME discuss whether we should let people change history # I’m in favour of leaving things as flexible as possible (@ali-graham) before_destroy :only_destroy_future def only_destroy_future (self.start_time.to_i - Time.now.to_i) > 0 end.
- #positive_duration ⇒ Object
- #tag=(t) ⇒ Object
Class Method Details
.jsonapi_associations ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/flapjack/data/scheduled_maintenance.rb', line 217 def self.jsonapi_associations unless instance_variable_defined?('@jsonapi_associations') @jsonapi_associations = { :check => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new( :post => true, :get => true, :number => :singular, :link => true, :includable => true, :descriptions => { :post => "Set a check for scheduled maintenance on creation.", :get => "Returns the check a scheduled maintenance period applies to." } ), :tag => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new( :post => true, :number => :singular, :link => false, :includable => false, :type => 'tag', :klass => Flapjack::Data::Tag, :descriptions => { :post => "Set scheduled maintenance on multiple checks on creation." } ) } populate_association_data(@jsonapi_associations) end @jsonapi_associations end |
.jsonapi_methods ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/flapjack/data/scheduled_maintenance.rb', line 185 def self.jsonapi_methods @jsonapi_methods ||= { :post => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :attributes => [:start_time, :end_time, :summary], :descriptions => { :singular => "Create a scheduled maintenance period for a check, or checks associated with a tag.", :multiple => "Create scheduled maintenance periods for a check, or checks associated with a tag." } ), :get => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :attributes => [:start_time, :end_time, :summary], :descriptions => { :singular => "Get data for a scheduled maintenance period.", :multiple => "Get data for multiple scheduled maintenance periods." } ), :patch => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :attributes => [:start_time, :end_time, :summary], :descriptions => { :singular => "Update data for a scheduled maintenance period.", :multiple => "Update data for scheduled maintenance periods.", } ), :delete => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :descriptions => { :singular => "Delete a scheduled maintenance period.", :multiple => "Delete scheduled maintenance periods." } ) } end |
.swagger_included_classes ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/flapjack/data/scheduled_maintenance.rb', line 171 def self.swagger_included_classes # hack -- hardcoding for now [ Flapjack::Data::Check, Flapjack::Data::Contact, Flapjack::Data::Medium, Flapjack::Data::Rule, Flapjack::Data::ScheduledMaintenance, Flapjack::Data::State, Flapjack::Data::Tag, Flapjack::Data::UnscheduledMaintenance ] end |
Instance Method Details
#duration ⇒ Object
# FIXME discuss whether we should let people change history # I’m in favour of leaving things as flexible as possible (@ali-graham) before_destroy :only_destroy_future def only_destroy_future
(self.start_time.to_i - Time.now.to_i) > 0
end
87 88 89 |
# File 'lib/flapjack/data/scheduled_maintenance.rb', line 87 def duration self.end_time - self.start_time end |
#positive_duration ⇒ Object
57 58 59 60 61 |
# File 'lib/flapjack/data/scheduled_maintenance.rb', line 57 def positive_duration return if self.start_time.nil? || self.end_time.nil? || (self.start_time < self.end_time) errors.add(:end_time, "must be greater than start time") end |
#tag=(t) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/flapjack/data/scheduled_maintenance.rb', line 32 def tag=(t) raise "Scheduled maintenance not saved" unless persisted? raise "Scheduled maintenance already associated" unless check.nil? checks = t.checks unless checks.empty? tag_checks = checks.all self.check = tag_checks.shift tag_checks.each do |ch| sm = Flapjack::Data::ScheduledMaintenance.new(:start_time => self.start_time, :end_time => end_time, :summary => summary) sm.save sm.check = ch end end end |