Sha256: 321342449c9a507a8b79c51d4d9d6aa1f7b0d2da5abf24001ee20fcee32a78fc

Contents?: true

Size: 647 Bytes

Versions: 5

Compression:

Stored size: 647 Bytes

Contents

# This source file contains code for a basic sequential surrogate key generator

module ETL #:nodoc:
  module Generator #:nodoc:
    # Surrogate key generator.
    class SurrogateKeyGenerator < Generator
      # Initialize the generator
      def initialize(options={})
        if options[:query]
          @surrogate_key = ETL::ActiveRecord::Base.connection.select_value(options[:query])
          @surrogate_key = 0 if @surrogate_key.blank?
          @surrogate_key = @surrogate_key.to_i
        end
      end

      # Get the next surrogate key
      def next
        @surrogate_key ||= 0
        @surrogate_key += 1
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activewarehouse-etl-0.8.0 lib/etl/generator/surrogate_key_generator.rb
activewarehouse-etl-0.8.1 lib/etl/generator/surrogate_key_generator.rb
activewarehouse-etl-0.8.2 lib/etl/generator/surrogate_key_generator.rb
activewarehouse-etl-0.8.3 lib/etl/generator/surrogate_key_generator.rb
activewarehouse-etl-0.8.4 lib/etl/generator/surrogate_key_generator.rb