Class: Protokoll::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/protokoll/counter.rb

Class Method Summary collapse

Class Method Details

.next(object, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/protokoll/counter.rb', line 5

def self.next(object, options)
  element = Models::CustomAutoIncrement.find_or_create_by(build_attrs(object, options))

  element.counter = options[:start] if outdated?(element, options) || element.counter == 0
  element.counter += 1

  element.touch unless element.changed?
  element.save! if element.changed?

  element.save!

  Formater.new.format(element.counter, options)
end