Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Dan McClain committed Jun 15, 2012
1 parent 726b4dd commit 477340e
Showing 1 changed file with 87 additions and 49 deletions.
136 changes: 87 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,66 @@ ActiveRecord's data type handling.

### INET

create_table :testing do |t|
t.inet :inet_column
# or
t.inet :inet_column_1, :inet_column_2
# or
t.column :inet_column, :inet
end
```ruby
create_table :testing do |t|
t.inet :inet_column
# or
t.inet :inet_column_1, :inet_column_2
# or
t.column :inet_column, :inet
end
```

### CIDR

create_table :testing do |t|
t.cidr :cidr_column
# or
t.cidr :cidr_column_1, :cidr_column_2
# or
t.column :cidr_column, :cidr
end
```ruby
create_table :testing do |t|
t.cidr :cidr_column
# or
t.cidr :cidr_column_1, :cidr_column_2
# or
t.column :cidr_column, :cidr
end
```

### MACADDR

create_table :testing do |t|
t.macaddr :macaddr_column
# or
t.macaddr :macaddr_column_1, :macaddr_column_2
# or
t.column :macaddr_column, :macaddr
end
```ruby
create_table :testing do |t|
t.macaddr :macaddr_column
# or
t.macaddr :macaddr_column_1, :macaddr_column_2
# or
t.column :macaddr_column, :macaddr
end
```

### UUID

create_table :testing do |t|
t.uuid :uuid_column
# or
t.uuid :uuid_column_1, :uuid_column_2
# or
t.column :uuid_column, :uuid
end
```ruby
create_table :testing do |t|
t.uuid :uuid_column
# or
t.uuid :uuid_column_1, :uuid_column_2
# or
t.column :uuid_column, :uuid
end
```

### Arrays
Arrays are created from any ActiveRecord supported datatype (including
ones added by postgre\_ext), and respect length constraints

create_table :testing do |t|
t.integer :int_array, :array => true
# integer[]
t.integer :int_array, :array => true, :length => 2
# smallint[]
t.string :macaddr_column_1, :array => true, :length => 30
# char varying(30)[]
end
```ruby
create_table :testing do |t|
t.integer :int_array, :array => true
# integer[]
t.integer :int_array, :array => true, :length => 2
# smallint[]
t.string :macaddr_column_1, :array => true, :length => 30
# char varying(30)[]
end
```

## Type Casting support

Expand All @@ -88,22 +98,50 @@ INET and CIDR values are converted to
[IPAddr](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ipaddr/rdoc/IPAddr.html)
objects when retrieved from the database, or set as a string.

create_table :inet_examples do |t|
t.inet :ip_address
end
```ruby
create_table :inet_examples do |t|
t.inet :ip_address
end

class InetExample < ActiveRecord::Base
end
class InetExample < ActiveRecord::Base
end

inetExample = InetExample.new
inetExample.ip_address = '127.0.0.0/24'
inetExample.ip_address
# => #<IPAddr: IPv4:127.0.0.0/255.255.255.0>
inetExample.save
inetExample = InetExample.new
inetExample.ip_address = '127.0.0.0/24'
inetExample.ip_address
# => #<IPAddr: IPv4:127.0.0.0/255.255.255.0>
inetExample.save

inet_2 = InetExample.first
inet_2.ip_address
# => #<IPAddr: IPv4:127.0.0.0/255.255.255.0>
inet_2 = InetExample.first
inet_2.ip_address
# => #<IPAddr: IPv4:127.0.0.0/255.255.255.0>
```

### Arrays
Array values can be set with Array objects. Any array stored in the
database will be converted to a properly casted array of values on the
way out.

```ruby
create_table :people do |t|
t.integer :favorite_numbers, :array => true
end

class Person < ActiveRecord::Base
end

person = Person.new
person.favorite_numbers = [1,2,3]
person.favorite_numbers
# => [1,2,3]
person.save

person_2 = Person.first
person_2.favoite_numbers
# => [1,2,3]
person_2.favoite_numbers.first.class
# => Fixnum
```

## Authors

Expand Down

0 comments on commit 477340e

Please sign in to comment.