class Flapjack::Data::ScheduledMaintenance

Public Class Methods

jsonapi_associations() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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

Public Instance Methods

duration() click to toggle source

# 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

# File lib/flapjack/data/scheduled_maintenance.rb, line 87
def duration
  self.end_time - self.start_time
end
positive_duration() click to toggle source
# 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) click to toggle source
# 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