Class: AutoIncrement::Incrementor

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_increment/incrementor.rb

Overview

AutoIncrement::Incrementor

Instance Method Summary collapse

Constructor Details

#initialize(column = nil, options = {}) ⇒ Incrementor

Returns a new instance of Incrementor.



5
6
7
8
9
10
11
12
13
14
# File 'lib/auto_increment/incrementor.rb', line 5

def initialize(column = nil, options = {})
  if column.is_a? Hash
    options = column
    column = nil
  end

  @column = column || options[:column] || :code
  @options = options.reverse_merge scope: nil, initial: 1, force: false
  @options[:scope] = [@options[:scope]] unless @options[:scope].is_a? Array
end

Instance Method Details

#before_create(record) ⇒ Object



16
17
18
19
# File 'lib/auto_increment/incrementor.rb', line 16

def before_create(record)
  @record = record
  write if can_write?
end