### Home Classes Methods

### In Files

- lib/dbi/columninfo.rb

### Parent

DelegateClass(Hash)

### Methods

- ::new
- #[]
- #[]=
- #default
- #method_missing

### Included Modules

- Deprecated

### Files

- README

### Class/Module Index

Quicksearch

- DBI
- DBI::BaseDatabase
- DBI::BaseDriver
- DBI::BaseStatement
- DBI::Binary
- DBI::ColumnInfo
- DBI::DataError
- DBI::DatabaseError
- DBI::DatabaseHandle
- DBI::Date
- DBI::DriverHandle
- DBI::Error
- DBI::Handle
- DBI::HandleTracer
- DBI::IntegrityError
- DBI::InterfaceError
- DBI::InternalError
- DBI::NotImplementedError
- DBI::NotSupportedError
- DBI::OperationalError
- DBI::ProgrammingError
- DBI::Row
- DBI::SQL
- DBI::SQL::PreparedStatement
- DBI::StatementHandle
- DBI::Time
- DBI::Timestamp
- DBI::Type
- DBI::Type::Boolean
- DBI::Type::Decimal
- DBI::Type::Float
- DBI::Type::Integer
- DBI::Type::Null
- DBI::Type::Timestamp
- DBI::Type::Varchar
- DBI::TypeUtil
- DBI::Utils
- DBI::Utils::ConvParam
- DBI::Utils::TableFormatter
- DBI::Utils::XMLFormatter
- DBI::Warning
- Class

No matching classes.

# DBI::ColumnInfo

This represents metadata for columns within a given table, such as the data type, whether or not the the column is a primary key, etc.

ColumnInfo is a delegate of Hash, but represents its keys indifferently, coercing all strings to symbols. It also has ostruct-like features, f.e.:

    h = ColumnInfo.new({ "foo" => "bar" })
    h[:foo] => "bar"
    h["foo"] => "bar"
    h.foo => "bar"

All of these forms have assignment forms as well.

### Public Class Methods

new(hash=nil) click to toggle source

Create a new ColumnInfo object.

If no Hash is provided, one will be created for you. The hash will be shallow cloned for storage inside the object, and an attempt will be made to convert all string keys to symbols.

In the event that both string and symbol keys are provided in the initial hash, we cannot safely route around collisions and therefore a TypeError is raised.

    # File lib/dbi/columninfo.rb, line 31
    def initialize(hash=nil)
        @hash = hash.dup rescue nil
        @hash ||= Hash.new

        # coerce all strings to symbols
        @hash.keys.each do |x|
            if x.kind_of? String
                sym = x.to_sym
                if @hash.has_key? sym
                    raise ::TypeError,
                        "#{self.class.name} may construct from a hash keyed with strings or symbols, but not both"
                end
                @hash[sym] = @hash[x]
                @hash.delete(x)
            end
        end

        super(@hash)
    end

### Public Instance Methods

[](key) click to toggle source

    # File lib/dbi/columninfo.rb, line 51
    def [](key)
        @hash[key.to_sym]
    end

[]=(key, value) click to toggle source

    # File lib/dbi/columninfo.rb, line 55
    def []=(key, value)
        @hash[key.to_sym] = value
    end

default() click to toggle source

    # File lib/dbi/columninfo.rb, line 59
    def default() # :nodoc; XXX hack to get around Hash#default
        method_missing(:default)
    end

method_missing(sym, value=nil) click to toggle source

    # File lib/dbi/columninfo.rb, line 63
    def method_missing(sym, value=nil)
        if sym.to_s =~ /=$/
            sym = sym.to_s.sub(/=$/, '').to_sym
            @hash[sym] = value
        elsif sym.to_s =~ /\?$/
            sym = sym.to_s.sub(/\?$/, '').to_sym
            @hash[sym]
        else
            @hash[sym]
        end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.