Class: Rea::Identifier

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/rea/identifier.rb

Constant Summary collapse

SEM =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#generateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/rea/identifier.rb', line 10

def generate
  SEM.synchronize do
    self.class.transaction do
      if value_reset_rule
        self.last_value = 0 if self.instance_eval(value_reset_rule)
      end
      self.last_value = (self.last_value) || 0
      self.last_value = self.last_value + 1
      self.save!
      self.instance_eval "\"#{id_rule}\""
    end
  end
end