Sha256: 7aa6a2f80ea0559bb150d2a27b81be7c0ec639926cd3c9bf1bb0b54cd8203680

Contents?: true

Size: 1.57 KB

Versions: 18

Compression:

Stored size: 1.57 KB

Contents

module FakeRecord
  class Column < Struct.new(:name, :type)
  end

  class Connection
    attr_reader :tables

    def initialize
      @tables = %w{ users photos developers }
      @columns = {
        'users' => [
          Column.new('id', :integer),
          Column.new('name', :string),
          Column.new('bool', :boolean),
          Column.new('created_at', :date),
        ]
      }
      @primary_keys = {
        'users' => 'id'
      }
    end

    def primary_key name
      @primary_keys[name.to_s]
    end

    def table_exists? name
      @tables.include? name.to_s
    end

    def columns name, message = nil
      @columns[name.to_s]
    end

    def quote_table_name name
      "\"#{name.to_s}\""
    end

    def quote_column_name name
      "\"#{name.to_s}\""
    end

    def quote thing, column = nil
      if column && column.type == :integer
        return 'NULL' if thing.nil?
        return thing.to_i
      end

      case thing
      when true
        "'t'"
      when false
        "'f'"
      when nil
        'NULL'
      when Numeric
        thing
      else
        "'#{thing}'"
      end
    end
  end

  class ConnectionPool
    class Spec < Struct.new(:config)
    end

    attr_reader :spec, :connection

    def initialize
      @spec = Spec.new(:adapter => 'america')
      @connection = Connection.new
    end

    def with_connection
      yield connection
    end
  end

  class Base
    attr_accessor :connection_pool

    def initialize
      @connection_pool = ConnectionPool.new
    end

    def connection
      connection_pool.connection
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
arel-2.0.10 test/support/fake_record.rb
square-arel-2.0.9.20110222133018 test/support/fake_record.rb
arel-2.0.9 test/support/fake_record.rb
arel-2.0.9.rc1 test/support/fake_record.rb
arel-2.0.8 test/support/fake_record.rb
arel-2.0.8.beta.20110131120940 test/support/fake_record.rb
ar-sybase-jdbc-adapter-0.2.0 test/support/fake_record.rb
arel-2.0.7 test/support/fake_record.rb
ar-sybase-jdbc-adapter-0.1.1 test/support/fake_record.rb
ar-sybase-jdbc-adapter-0.1.0 test/support/fake_record.rb
ar-sybase-jdbc-adapter-0.0.2 test/support/fake_record.rb
arel-2.0.7.beta.20110110114925 test/support/fake_record.rb
ar-sybase-jdbc-adapter-0.0.1 test/support/fake_record.rb
arel-2.0.6 test/support/fake_record.rb
arel-2.0.5 test/support/fake_record.rb
arel-2.0.4 test/support/fake_record.rb
arel-2.0.3 test/support/fake_record.rb
arel-2.0.2 test/support/fake_record.rb