diff --git a/README.md b/README.md index 892ed58..2b83773 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 - # => # - inetExample.save +inetExample = InetExample.new +inetExample.ip_address = '127.0.0.0/24' +inetExample.ip_address +# => # +inetExample.save - inet_2 = InetExample.first - inet_2.ip_address - # => # +inet_2 = InetExample.first +inet_2.ip_address +# => # +``` + +### 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