Class: Firefly::CodeFactory

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/firefly/code_factory.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.orderObject

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