class Porpoise::KeyValueObject
Constants
- DEADLOCK_RETRY_COUNT
:nocov:
Public Class Methods
retry_lock_error(retries = 20) { || ... }
click to toggle source
# File lib/porpoise/key_value_object.rb, line 38 def self.retry_lock_error(retries = 20, &block) begin yield rescue ActiveRecord::StatementInvalid => e if e.message =~ /Deadlock found when trying to get lock/ and (retries.nil? || retries > 0) retry_lock_error(retries ? retries - 1 : nil, &block) else raise e end end end
Public Instance Methods
expired?()
click to toggle source
# File lib/porpoise/key_value_object.rb, line 50 def expired? !self.expiration_date.nil? && self.expiration_date < Time.now end
save()
click to toggle source
Calls superclass method
# File lib/porpoise/key_value_object.rb, line 54 def save super rescue ActiveRecord::RecordNotUnique # catch race conditions o = Porpoise::KeyValueObject.not_expired.where(key: self.key).first o.value = self.value o.expiration_date = self.expiration_date o.save end
Private Instance Methods
check_data_type()
click to toggle source
# File lib/porpoise/key_value_object.rb, line 66 def check_data_type if !self.data_type.nil? && self.value.class.name != self.data_type raise Porpoise::TypeMismatch.new( "#{self.value.class.name} is not of type #{self.data_type}" ) end end
set_data_type()
click to toggle source
# File lib/porpoise/key_value_object.rb, line 74 def set_data_type self.data_type = self.value.class.name end