Class: Cranium::Transformation::Sequence
- Inherits:
-
Object
- Object
- Cranium::Transformation::Sequence
- Defined in:
- lib/cranium/transformation/sequence.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(name) ⇒ Sequence
constructor
A new instance of Sequence.
- #next_value ⇒ Object
Constructor Details
#initialize(name) ⇒ Sequence
Returns a new instance of Sequence.
7 8 9 |
# File 'lib/cranium/transformation/sequence.rb', line 7 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/cranium/transformation/sequence.rb', line 3 def name @name end |
Class Method Details
.by_name(name) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/cranium/transformation/sequence.rb', line 31 def by_name(name) @sequences ||= {} if @sequences[name].nil? @sequences[name] = new name Cranium.application.after_import { @sequences[name].flush } end @sequences[name] end |
Instance Method Details
#flush ⇒ Object
23 24 25 |
# File 'lib/cranium/transformation/sequence.rb', line 23 def flush Cranium::Database.connection.run "SELECT setval('#{@name}', #{@current_value})" unless @current_value.nil? end |
#next_value ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/cranium/transformation/sequence.rb', line 13 def next_value if @current_value.nil? @current_value = Cranium::Database.connection["SELECT nextval('#{@name}') AS next_value"].first[:next_value] else @current_value += 1 end end |