Sha256: d5465650e090ceaa1a2858ba14015ae1e3f5be33226147679182a4cd21eb8c88

Contents?: true

Size: 678 Bytes

Versions: 1

Compression:

Stored size: 678 Bytes

Contents

require "active_record/base"

module DocumentNumber
  class Numerator
    def self.next_number(object, options)
      DocumentNumber.transaction do
        if ::Rails.version < "4.0"
          # Rails 3 support
          document_number = DocumentNumber.lock(true).find_or_initialize_by_document(object.class.to_s.underscore)
        else
          document_number = DocumentNumber.lock(true).find_or_initialize_by(:document => object.class.to_s.underscore)
        end

        number = document_number.number == 1 ? options[:start] : document_number.number

        document_number.number = number + 1
        document_number.save!

        number
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
document_number-0.9.4 lib/document_number/numerator.rb