0.0
No commit activity in last 3 years
No release in over 3 years
Document Number lets you automacally assign number sequences for your rails model
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.3
~> 0.9
~> 4.0
~> 10.3
~> 3.5
~> 1.3

Runtime

< 5.0, >= 3.0
 Project Readme

Document Number

Circle CI

Document Number lets you automacally assign number sequences for your rails models.

Installation

Rails 3 & 4

  1. Add Document Number to your Gemfile

    gem 'document_number', '~> 0.10.0'

  2. Generate a migration which will add a document_numbers table to your database

    bundle exec rails generate document_numbers:install

  3. Run the migration

    bundle exec rake db:migrate

  4. Declare has_document_number in your model to automatic document number assignment:

class Invoice < ActiveRecord::Base
  has_document_number
end

Configuring Document Number

Document Number has several configuration options, which you can configure, both globally and on a per-model basis:

# config/initializers/document_number.rb
DocumentNumber.prefix = 'server/'

Or alternatively:

class Invoice < ActiveRecord::Base
  has_document_number prefix: 'server/', start: 5000
end

Available options:

Option Description
column The column name to update. Default value is :number
prefix The prefix for number
start The start value for number. Default is 1

Usage

Get number after initialization

Document Number automacally assigns number when you saving your model. If you want to create number just after initialization use :with_number attribute:

Invoice.new with_number: true

Preserve numbers

If you want to get a bunch of numbers use model method get_numbers:

irb(main):001>Invoice.get_numbers(3)
=> ['server/1', 'server/2', 'server/3']

Contribute

Feel free to add any new features or fix bugs by creating a new pull request to this repository

Run tests

bundle exec rspec