Module: Ixtlan::Optimistic::StaleCheck

Defined in:
lib/ixtlan/optimistic/stale_check.rb

Instance Method Summary collapse

Instance Method Details

#__check(updated_at) ⇒ Object



26
27
28
29
30
# File 'lib/ixtlan/optimistic/stale_check.rb', line 26

def __check( updated_at )
  unless updated_at
    raise ObjectStaleException.new "no 'updated_at' given for #{self}."
  end
end

#__check_stale(updated_at, result) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ixtlan/optimistic/stale_check.rb', line 32

def __check_stale( updated_at, result )
  if updated_at.is_a? String
    updated_at = DateTime.parse( updated_at.sub(/[.][0-9]+/, '') )
  end
  if defined?( ActiveSupport::TimeWithZone ) && updated_at.is_a?( ActiveSupport::TimeWithZone )
    updated_at = updated_at.to_datetime
  end
  updated_at = updated_at.new_offset(0)
  if updated_at != result.updated_at && updated_at.strftime("%Y:%m:%d %H:%M:%S") != result.updated_at.strftime("%Y:%m:%d %H:%M:%S")
    
    raise ObjectStaleException.new "#{result.model} with key [#{result.id}] was updated at #{result.updated_at} is newer than the given one which was updated at #{updated_at}."
  end
  result
end