Class: Rea::Identifier
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Rea::Identifier
- Defined in:
- app/models/rea/identifier.rb
Constant Summary collapse
- SEM =
Mutex.new
Instance Method Summary collapse
Instance Method Details
#generate ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/rea/identifier.rb', line 18 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 id = self.instance_eval "\"#{id_rule}\"" self.last_value = next_value self.save! return id end end end |
#next_id ⇒ Object
10 11 12 |
# File 'app/models/rea/identifier.rb', line 10 def next_id self.instance_eval "\"#{id_rule}\"" if id_rule end |
#next_value ⇒ Object
14 15 16 |
# File 'app/models/rea/identifier.rb', line 14 def next_value last_value + 1 end |