Sha256: 269ae6f0d21681e4a8e7908f1448996515b78d2c4bc7c701fc93f1d36d622803

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

# This source file contains extensions to the abstract adapter.
module ActiveRecord #:nodoc:
  module ConnectionAdapters #:nodoc:
    # Extensions to the AbstractAdapter. In some cases a default implementation
    # is provided, in others it is adapter-dependent and the method will
    # raise a NotImplementedError if the adapter does not implement that method
    class AbstractAdapter
      # Truncate the specified table
      def truncate(table_name)
        execute("TRUNCATE TABLE #{table_name}")
      end
      
      # Bulk loading interface. Load the data from the specified file into the
      # given table. Note that options will be adapter-dependent.
      def bulk_load(file, table_name, options={})
        raise ArgumentError, "#{file} does not exist" unless File.exist?(file)
        raise ArgumentError, "#{table_name} does not exist" unless tables.include?(table_name)
        do_bulk_load(file, table_name, options)
      end
      
      protected
      
      # for subclasses to implement
      def do_bulk_load(file, table_name, options={})
        raise NotImplementedError, "do_bulk_load is an abstract method"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adapter_extensions-0.2.0 lib/adapter_extensions/connection_adapters/abstract_adapter.rb
adapter_extensions-0.3.0 lib/adapter_extensions/connection_adapters/abstract_adapter.rb