Sha256: 3b9f2df28152c416043719a7c2c054d8b7df13651e6e55e549d65393d8dd5f2b

Contents?: true

Size: 1.25 KB

Versions: 28

Compression:

Stored size: 1.25 KB

Contents

module Perus::Server
    class Config < Sequel::Model
        plugin :validation_helpers
        one_to_many :systems
        one_to_many :config_metrics, order: :order

        def metric_hashes
            config_metrics.collect(&:config_hash)
        end

        def largest_order
            if config_metrics.empty?
                0
            else
                config_metrics.last.order
            end
        end

        def can_delete?
            systems_dataset.empty?
        end

        def in_maintenance?
            return false unless maintenance.is_a?(String)
            from, to = maintenance.split('-')
            now = Time.now

            from_hour, from_min = from.split(':').map(&:to_i)
            return false if now.hour < from_hour
            return false if now.hour == from_hour && now.min < from_min

            to_hour, to_min = to.split(':').map(&:to_i)
            return false if now.hour > to_hour
            return false if now.hour == to_hour && now.min > to_min

            true
        end

        def validate
            super
            validates_presence  :name
            validates_unique    :name
        end

        def after_destroy
            super
            config_metrics.each(&:destroy)
        end
    end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
perus-1.0.7 lib/perus/server/models/config.rb
perus-1.0.6 lib/perus/server/models/config.rb
perus-1.0.5 lib/perus/server/models/config.rb
perus-1.0.4 lib/perus/server/models/config.rb
perus-1.0.3 lib/perus/server/models/config.rb
perus-1.0.2 lib/perus/server/models/config.rb
perus-1.0.1 lib/perus/server/models/config.rb
perus-1.0.0 lib/perus/server/models/config.rb
perus-0.1.35 lib/perus/server/models/config.rb
perus-0.1.34 lib/perus/server/models/config.rb
perus-0.1.33 lib/perus/server/models/config.rb
perus-0.1.32 lib/perus/server/models/config.rb
perus-0.1.31 lib/perus/server/models/config.rb
perus-0.1.30 lib/perus/server/models/config.rb
perus-0.1.29 lib/perus/server/models/config.rb
perus-0.1.28 lib/perus/server/models/config.rb
perus-0.1.27 lib/perus/server/models/config.rb
perus-0.1.26 lib/perus/server/models/config.rb
perus-0.1.25 lib/perus/server/models/config.rb
perus-0.1.24 lib/perus/server/models/config.rb