Class: Firefly::CodeFactory
- Inherits:
-
Object
- Object
- Firefly::CodeFactory
- Includes:
- DataMapper::Resource
- Defined in:
- lib/firefly/code_factory.rb
Class Attribute Summary collapse
-
.order ⇒ Object
Returns the value of attribute order.
Class Method Summary collapse
-
.next_code! ⇒ Object
Redirect to the selected order method.
-
.next_random_code! ⇒ Object
Returns the next value randomly.
-
.next_sequential_code! ⇒ Object
Returns the next auto increment value and updates the counter.
Class Attribute Details
.order ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'lib/firefly/code_factory.rb', line 5 def order @order end |
Class Method Details
.next_code! ⇒ Object
Redirect to the selected order method
14 15 16 |
# File 'lib/firefly/code_factory.rb', line 14 def self.next_code! self.send("next_#{self.order || :sequential}_code!".to_sym) end |
.next_random_code! ⇒ Object
Returns the next value randomly
19 20 21 |
# File 'lib/firefly/code_factory.rb', line 19 def self.next_random_code! Firefly::Base62.encode(rand(200000000)) end |
.next_sequential_code! ⇒ Object
Returns the next auto increment value and updates the counter
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/firefly/code_factory.rb', line 25 def self.next_sequential_code! code = nil Firefly::CodeFactory.transaction do c = Firefly::CodeFactory.first code = Firefly::Base62.encode(c.count + 1) c.update(:count => c.count + 1) end code end |