Sha256: cf4e05ee6ffb8e37161a25c72acd1459b7bd8b965186db26fd0d0b06fdf26bc2

Contents?: true

Size: 540 Bytes

Versions: 1

Compression:

Stored size: 540 Bytes

Contents

module Transit
  module Model
    ##
    # Provides SQL like auto-incrementing of an id using a "uid" field
    # 
    module AutoIncrement
      extend ActiveSupport::Concern
      
      included do
        field :uid, :type => Integer
        before_create :generate_uid, :on => :create
      end
      
      def generate_uid
        return true unless self.uid.nil?        
        ref = (self.class.superclass == Object ? self.class : self.class.superclass)
        self.uid = ref.max(:uid).to_i + 1
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
transit-0.0.2 lib/transit/model/auto_increment.rb