<commit_before><commit_msg>README.<commit_after>auto_increment
==============

auto_increment provides automatic incrementation for a string or integer fields in Rails.

Installation
------------

You can use auto_increment as a gem in Rails 3.

To use the gem version, put the following gem requirement in your `Gemfile`:

    gem "auto_increment"


Usage
-----

To work with a auto increment column you used to do sometihng like this in your model:

    before_create :set_code
    def set_code
      max_code = Operation.maximum(:code)
      self.code = max_code.to_i + 1
    end

Looks fine, but not when you need to do it over and over again. In fact auto_increment does it under the cover.

All you need to do is this:

    auto_increment

And your code field will be incremented


### Customizing

So you have a different column or need a scope. auto_increment provides options. You can use it like this:

    auto_increment :column => :letter, :scope => [:account_id, :job_id], :initial => 'C', :force => true

* column: the column that will be incremented. Can be integer os string (default: code)
* scope: you can define columns that will be scoped and you can use as many as you want (default: nil)
* initial: initial value of column (default: 1)
* force: you can set a value before create and auto_increment will not change that, but if you do want this, set force to true (default: false)


### Compatibility

* Tested with Rails 3.0.4 in Ruby 1.8.7 and Ruby 1.9.2

### License
MIT License. Copyright 2011 29sul Tecnologia da Informação <http://www.29sul.com.br/>
{'fraction_non_alphanumeric': 0.08629441624365482, 'fraction_numerical': 0.012690355329949238, 'mean_word_length': 3.6519174041297937, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4068545', 'n_tokens_mistral': 482, 'n_tokens_neox': 454, 'n_words': 222}