Sha256: d51a3d7152d74750c0a169b64f81d20e06e745bb70ecd24ddbbfe95fd4462747

Contents?: true

Size: 707 Bytes

Versions: 13

Compression:

Stored size: 707 Bytes

Contents

class Cranium::Transformation::Sequence

  attr_reader :name



  def initialize(name)
    @name = name
  end



  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



  def flush
    Cranium::Database.connection.run "SELECT setval('#{@name}', #{@current_value})" unless @current_value.nil?
  end



  class << self

    def by_name(name)
      @sequences ||= {}
      if @sequences[name].nil?
        @sequences[name] = new name
        Cranium.application.after_import { @sequences[name].flush }
      end
      @sequences[name]
    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cranium-0.8.1 lib/cranium/transformation/sequence.rb
cranium-0.8 lib/cranium/transformation/sequence.rb
cranium-0.7 lib/cranium/transformation/sequence.rb
cranium-0.6.1 lib/cranium/transformation/sequence.rb
cranium-0.5 lib/cranium/transformation/sequence.rb
cranium-0.4.3 lib/cranium/transformation/sequence.rb
cranium-0.4.2 lib/cranium/transformation/sequence.rb
cranium-0.4.1 lib/cranium/transformation/sequence.rb
cranium-0.4 lib/cranium/transformation/sequence.rb
cranium-0.3.1 lib/cranium/transformation/sequence.rb
cranium-0.3.0 lib/cranium/transformation/sequence.rb
cranium-0.2.1 lib/cranium/transformation/sequence.rb
cranium-0.2.0 lib/cranium/transformation/sequence.rb