lib/cosmos/packets/packet_item_limits.rb in cosmos-4.5.2-java vs lib/cosmos/packets/packet_item_limits.rb in cosmos-5.0.2.pre.beta2

- old
+ new

@@ -1,19 +1,27 @@ # encoding: ascii-8bit -# Copyright 2014 Ball Aerospace & Technologies Corp. +# Copyright 2022 Ball Aerospace & Technologies Corp. # All Rights Reserved. # # This program is free software; you can modify and/or redistribute it -# under the terms of the GNU General Public License +# under the terms of the GNU Affero General Public License # as published by the Free Software Foundation; version 3 with # attribution addendums as found in the LICENSE.txt +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# This program may also be used under the terms of a commercial or +# enterprise edition license of COSMOS if purchased from the +# copyright holder require 'cosmos/packets/limits_response' module Cosmos - # Maintains knowledge of limits for a PacketItem class PacketItemLimits # Array of all limit states LIMITS_STATES = [:RED, :RED_HIGH, :RED_LOW, :YELLOW, :YELLOW_HIGH, :YELLOW_LOW, :GREEN, :GREEN_HIGH, :GREEN_LOW, :BLUE, :STALE, nil] # Array of all limit states which should be considered in error @@ -68,37 +76,52 @@ def values=(values) if values raise ArgumentError, "values must be a Hash but is a #{values.class}" unless Hash === values raise ArgumentError, "values must be a Hash with a :DEFAULT key" unless values.keys.include?(:DEFAULT) + @values = values.clone else @values = nil end end def state=(state) raise ArgumentError, "state must be one of #{LIMITS_STATES} but is #{state}" unless LIMITS_STATES.include?(state) + @state = state end def response=(response) if response raise ArgumentError, "response must be a Cosmos::LimitsResponse but is a #{response.class}" unless Cosmos::LimitsResponse === response + @response = response.clone else @response = nil end end def persistence_setting=(persistence_setting) - raise ArgumentError, "persistence_setting must be an Integer but is a #{persistence_setting.class}" unless Integer === persistence_setting + if 0.class == Integer + # Ruby version >= 2.4.0 + raise ArgumentError, "persistence_setting must be an Integer but is a #{persistence_setting.class}" unless Integer === persistence_setting + else + # Ruby version < 2.4.0 + raise ArgumentError, "persistence_setting must be a Fixnum but is a #{persistence_setting.class}" unless Fixnum === persistence_setting + end @persistence_setting = persistence_setting end def persistence_count=(persistence_count) - raise ArgumentError, "persistence_count must be an Integer but is a #{persistence_count.class}" unless Integer === persistence_count + if 0.class == Integer + # Ruby version >= 2.4.0 + raise ArgumentError, "persistence_count must be an Integer but is a #{persistence_count.class}" unless Integer === persistence_count + else + # Ruby version < 2.4.0 + raise ArgumentError, "persistence_count must be a Fixnum but is a #{persistence_count.class}" unless Fixnum === persistence_count + end @persistence_count = persistence_count end # Make a light weight clone of this limits def clone @@ -121,8 +144,7 @@ end hash['persistence_setting'] = self.persistence_setting hash['persistence_count'] = self.persistence_count hash end - end end # module Cosmos