Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bit

Inherits:
Type::Value
  • Object
show all
Defined in:
lib/active_record/connection_adapters/postgresql/oid/bit.rb

Overview

:nodoc:

Direct Known Subclasses

BitVarying

Defined Under Namespace

Classes: Data

Instance Attribute Summary

Attributes inherited from Type::Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods inherited from Type::Value

#==, #binary?, #changed?, #changed_in_place?, #initialize, #klass, #number?, #text?, #type_cast_for_schema, #type_cast_from_database, #type_cast_from_user

Constructor Details

This class inherits a constructor from ActiveRecord::Type::Value

Instance Method Details

#typeObject



6
7
8
# File 'lib/active_record/connection_adapters/postgresql/oid/bit.rb', line 6

def type
  :bit
end

#type_cast(value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_record/connection_adapters/postgresql/oid/bit.rb', line 10

def type_cast(value)
  if ::String === value
    case value
    when /^0x/i
      value[2..-1].hex.to_s(2) # Hexadecimal notation
    else
      value                    # Bit-string notation
    end
  else
    value
  end
end

#type_cast_for_database(value) ⇒ Object



23
24
25
# File 'lib/active_record/connection_adapters/postgresql/oid/bit.rb', line 23

def type_cast_for_database(value)
  Data.new(super) if value
end