Sha256: c96cc84ab394d60599045daa53b6fdc40ab09c9dcf06d9319ce126bcc52e775f

Contents?: true

Size: 800 Bytes

Versions: 8

Compression:

Stored size: 800 Bytes

Contents

module Ixtlan
  module Core
    module OptimisticActiveRecord

      def self.included(base)
        base.class_eval do

          attr_accessor :current_user

          def self.optimistic_find(updated_at, *args)
            if updated_at
              updated_at_date = new(:updated_at => updated_at).updated_at
              # try different ways to use the date
              # TODO maybe there is a nicer way ??
              first(:conditions => ["id = ? and updated_at <= ? and updated_at >= ?", args[0], updated_at, updated_at_date - 0.001]) || first(:conditions => ["id = ? and updated_at <= ? and updated_at >= ?", args[0], updated_at_date, updated_at_date - 0.001])
              # TODO make it work with different PKs
            end
          end

        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ixtlan-core-0.8.0 lib/ixtlan/core/active_record.rb~
ixtlan-core-0.7.5 lib/ixtlan/core/active_record.rb~
ixtlan-core-0.7.4 lib/ixtlan/core/active_record.rb~
ixtlan-core-0.7.3 lib/ixtlan/core/active_record.rb~
ixtlan-core-0.7.2 lib/ixtlan/core/active_record.rb~
ixtlan-core-0.7.1 lib/ixtlan/core/active_record.rb~
ixtlan-core-0.7.0 lib/ixtlan/core/active_record.rb~
ixtlan-core-0.6.1 lib/ixtlan/core/active_record.rb~