public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Cleanup whitespace and change_table documentation
thetamind (author)
Sun May 11 14:46:07 -0700 2008
commit  35634feb474cc55fbc95edeffe98cec241d45f23
tree    9f9091817f8ff0947397dfb223d9e0b0a5576251
parent  f4aaa2e99c350466e54afefdf278b4ba04008cd9
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@
0
 
0
     change_table :videos do |t|
0
       t.timestamps # adds created_at, updated_at
0
- t.belongs_to :goat # add goat_id integer
0
+ t.belongs_to :goat # adds goat_id integer
0
       t.string :name, :email, :limit => 20 # adds name and email both with a 20 char limit
0
       t.remove :name, :email # removes the name and email columns
0
     end
...
18
19
20
21
 
22
23
24
25
 
26
27
28
...
172
173
174
175
 
176
177
178
...
250
251
252
253
 
254
255
256
257
 
258
259
260
...
309
310
311
312
 
313
314
315
 
316
317
 
318
319
320
321
322
323
324
 
325
326
 
327
328
 
329
330
331
332
 
333
334
 
335
336
 
337
338
339
 
340
341
342
 
343
344
 
345
346
347
...
394
395
396
397
 
398
399
400
...
434
435
436
437
 
438
439
440
441
442
443
 
 
444
445
446
...
458
459
460
461
 
462
463
464
...
510
511
512
513
514
 
 
515
516
517
518
519
520
521
 
 
522
523
524
...
531
532
533
534
535
 
 
536
537
538
...
547
548
549
550
 
551
552
553
...
559
560
561
562
563
564
565
566
567
 
568
569
 
 
570
571
 
572
573
 
574
575
 
576
577
578
579
580
581
582
 
583
584
585
...
592
593
594
595
596
597
 
 
 
598
599
600
601
602
603
...
609
610
611
612
613
614
615
616
 
 
 
617
 
618
619
620
...
627
628
629
630
 
631
632
633
...
18
19
20
 
21
22
23
24
 
25
26
27
28
...
172
173
174
 
175
176
177
178
...
250
251
252
 
253
254
255
256
 
257
258
259
260
...
309
310
311
 
312
313
314
 
315
316
 
317
318
319
320
321
322
323
 
324
325
 
326
327
 
328
329
330
331
 
332
333
 
334
335
 
336
337
338
 
339
340
341
 
342
343
 
344
345
346
347
...
394
395
396
 
397
398
399
400
...
434
435
436
 
437
438
439
440
441
 
 
442
443
444
445
446
...
458
459
460
 
461
462
463
464
...
510
511
512
 
 
513
514
515
516
517
518
519
 
 
520
521
522
523
524
...
531
532
533
 
 
534
535
536
537
538
...
547
548
549
 
550
551
552
553
...
559
560
561
 
562
563
564
565
 
566
567
 
568
569
570
 
571
572
 
573
574
 
575
576
577
578
579
580
581
 
582
583
584
585
...
592
593
594
 
 
 
595
596
597
598
599
 
600
601
602
...
608
609
610
 
 
 
 
 
611
612
613
614
615
616
617
618
...
625
626
627
 
628
629
630
631
0
@@ -18,11 +18,11 @@ module ActiveRecord
0
       #
0
       # +name+ is the column's name, as in <tt><b>supplier_id</b> int(11)</tt>.
0
       # +default+ is the type-casted default value, such as <tt>sales_stage varchar(20) default <b>'new'</b></tt>.
0
- # +sql_type+ is only used to extract the column's length, if necessary. For example, <tt>company_name varchar(<b>60</b>)</tt>.
0
+ # +sql_type+ is only used to extract the column's length, if necessary. For example, <tt>company_name varchar(<b>60</b>)</tt>.
0
       # +null+ determines if this column allows +NULL+ values.
0
       def initialize(name, default, sql_type = nil, null = true)
0
         @name, @sql_type, @null = name, sql_type, null
0
- @limit, @precision, @scale = extract_limit(sql_type), extract_precision(sql_type), extract_scale(sql_type)
0
+ @limit, @precision, @scale = extract_limit(sql_type), extract_precision(sql_type), extract_scale(sql_type)
0
         @type = simplified_type(sql_type)
0
         @default = extract_default(default)
0
 
0
@@ -172,7 +172,7 @@ module ActiveRecord
0
           def new_time(year, mon, mday, hour, min, sec, microsec)
0
             # Treat 0000-00-00 00:00:00 as nil.
0
             return nil if year.nil? || year == 0
0
-
0
+
0
             Time.time_with_datetime_fallback(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil
0
           end
0
 
0
@@ -250,11 +250,11 @@ module ActiveRecord
0
     end
0
 
0
     class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :precision, :scale, :default, :null) #:nodoc:
0
-
0
+
0
       def sql_type
0
         base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
0
       end
0
-
0
+
0
       def to_sql
0
         column_sql = "#{base.quote_column_name(name)} #{sql_type}"
0
         add_column_options!(column_sql, :null => null, :default => default) unless type.to_sym == :primary_key
0
@@ -309,39 +309,39 @@ module ActiveRecord
0
       # * <tt>:default</tt> -
0
       # The column's default value. Use nil for NULL.
0
       # * <tt>:null</tt> -
0
- # Allows or disallows +NULL+ values in the column. This option could
0
+ # Allows or disallows +NULL+ values in the column. This option could
0
       # have been named <tt>:null_allowed</tt>.
0
       # * <tt>:precision</tt> -
0
- # Specifies the precision for a <tt>:decimal</tt> column.
0
+ # Specifies the precision for a <tt>:decimal</tt> column.
0
       # * <tt>:scale</tt> -
0
- # Specifies the scale for a <tt>:decimal</tt> column.
0
+ # Specifies the scale for a <tt>:decimal</tt> column.
0
       #
0
       # Please be aware of different RDBMS implementations behavior with
0
       # <tt>:decimal</tt> columns:
0
       # * The SQL standard says the default scale should be 0, <tt>:scale</tt> <=
0
       # <tt>:precision</tt>, and makes no comments about the requirements of
0
       # <tt>:precision</tt>.
0
- # * MySQL: <tt>:precision</tt> [1..63], <tt>:scale</tt> [0..30].
0
+ # * MySQL: <tt>:precision</tt> [1..63], <tt>:scale</tt> [0..30].
0
       # Default is (10,0).
0
- # * PostgreSQL: <tt>:precision</tt> [1..infinity],
0
+ # * PostgreSQL: <tt>:precision</tt> [1..infinity],
0
       # <tt>:scale</tt> [0..infinity]. No default.
0
- # * SQLite2: Any <tt>:precision</tt> and <tt>:scale</tt> may be used.
0
+ # * SQLite2: Any <tt>:precision</tt> and <tt>:scale</tt> may be used.
0
       # Internal storage as strings. No default.
0
       # * SQLite3: No restrictions on <tt>:precision</tt> and <tt>:scale</tt>,
0
       # but the maximum supported <tt>:precision</tt> is 16. No default.
0
- # * Oracle: <tt>:precision</tt> [1..38], <tt>:scale</tt> [-84..127].
0
+ # * Oracle: <tt>:precision</tt> [1..38], <tt>:scale</tt> [-84..127].
0
       # Default is (38,0).
0
- # * DB2: <tt>:precision</tt> [1..63], <tt>:scale</tt> [0..62].
0
+ # * DB2: <tt>:precision</tt> [1..63], <tt>:scale</tt> [0..62].
0
       # Default unknown.
0
- # * Firebird: <tt>:precision</tt> [1..18], <tt>:scale</tt> [0..18].
0
+ # * Firebird: <tt>:precision</tt> [1..18], <tt>:scale</tt> [0..18].
0
       # Default (9,0). Internal types NUMERIC and DECIMAL have different
0
       # storage rules, decimal being better.
0
- # * FrontBase?: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38].
0
+ # * FrontBase?: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38].
0
       # Default (38,0). WARNING Max <tt>:precision</tt>/<tt>:scale</tt> for
0
       # NUMERIC is 19, and DECIMAL is 38.
0
- # * SqlServer?: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38].
0
+ # * SqlServer?: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38].
0
       # Default (38,0).
0
- # * Sybase: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38].
0
+ # * Sybase: <tt>:precision</tt> [1..38], <tt>:scale</tt> [0..38].
0
       # Default (38,0).
0
       # * OpenBase?: Documentation unclear. Claims storage in <tt>double</tt>.
0
       #
0
@@ -394,7 +394,7 @@ module ActiveRecord
0
       # t.timestamps
0
       # end
0
       #
0
- # There's a short-hand method for each of the type values declared at the top. And then there's
0
+ # There's a short-hand method for each of the type values declared at the top. And then there's
0
       # TableDefinition#timestamps that'll add created_at and updated_at as datetimes.
0
       #
0
       # TableDefinition#references will add an appropriately-named _id column, plus a corresponding _type
0
@@ -434,13 +434,13 @@ module ActiveRecord
0
           def #{column_type}(*args)
0
             options = args.extract_options!
0
             column_names = args
0
-
0
+
0
             column_names.each { |name| column(name, '#{column_type}', options) }
0
           end
0
         EOV
0
       end
0
-
0
- # Appends <tt>:datetime</tt> columns <tt>:created_at</tt> and
0
+
0
+ # Appends <tt>:datetime</tt> columns <tt>:created_at</tt> and
0
       # <tt>:updated_at</tt> to the table.
0
       def timestamps
0
         column(:created_at, :datetime)
0
@@ -458,7 +458,7 @@ module ActiveRecord
0
       alias :belongs_to :references
0
 
0
       # Returns a String whose contents are the column definitions
0
- # concatenated together. This string can then be prepended and appended to
0
+ # concatenated together. This string can then be prepended and appended to
0
       # to generate the final SQL to create the table.
0
       def to_sql
0
         @columns * ', '
0
@@ -510,15 +510,15 @@ module ActiveRecord
0
 
0
       # Adds a new column to the named table.
0
       # See TableDefinition#column for details of the options you can use.
0
- # ===== Examples
0
- # ====== Creating a simple columns
0
+ # ===== Example
0
+ # ====== Creating a simple column
0
       # t.column(:name, :string)
0
       def column(column_name, type, options = {})
0
         @base.add_column(@table_name, column_name, type, options)
0
       end
0
 
0
- # Adds a new index to the table. +column_name+ can be a single Symbol, or
0
- # an Array of Symbols. See SchemaStatements#add_index
0
+ # Adds a new index to the table. +column_name+ can be a single Symbol, or
0
+ # an Array of Symbols. See SchemaStatements#add_index
0
       #
0
       # ===== Examples
0
       # ====== Creating a simple index
0
@@ -531,8 +531,8 @@ module ActiveRecord
0
         @base.add_index(@table_name, column_name, options)
0
       end
0
 
0
- # Adds timestamps (created_at and updated_at) columns to the table. See SchemaStatements#timestamps
0
- # ===== Examples
0
+ # Adds timestamps (created_at and updated_at) columns to the table. See SchemaStatements#add_timestamps
0
+ # ===== Example
0
       # t.timestamps
0
       def timestamps
0
         @base.add_timestamps(@table_name)
0
@@ -547,7 +547,7 @@ module ActiveRecord
0
         @base.change_column(@table_name, column_name, type, options)
0
       end
0
 
0
- # Sets a new default value for a column. See
0
+ # Sets a new default value for a column. See SchemaStatements#change_column_default
0
       # ===== Examples
0
       # t.change_default(:qualification, 'new')
0
       # t.change_default(:authorized, 1)
0
@@ -559,27 +559,27 @@ module ActiveRecord
0
       # ===== Examples
0
       # t.remove(:qualification)
0
       # t.remove(:qualification, :experience)
0
- # t.removes(:qualification, :experience)
0
       def remove(*column_names)
0
         @base.remove_column(@table_name, column_names)
0
       end
0
 
0
- # Remove the given index from the table.
0
+ # Removes the given index from the table.
0
       #
0
- # Remove the suppliers_name_index in the suppliers table.
0
+ # ===== Examples
0
+ # ====== Remove the suppliers_name_index in the suppliers table
0
       # t.remove_index :name
0
- # Remove the index named accounts_branch_id_index in the accounts table.
0
+ # ====== Remove the index named accounts_branch_id_index in the accounts table
0
       # t.remove_index :column => :branch_id
0
- # Remove the index named accounts_branch_id_party_id_index in the accounts table.
0
+ # ====== Remove the index named accounts_branch_id_party_id_index in the accounts table
0
       # t.remove_index :column => [:branch_id, :party_id]
0
- # Remove the index named by_branch_party in the accounts table.
0
+ # ====== Remove the index named by_branch_party in the accounts table
0
       # t.remove_index :name => :by_branch_party
0
       def remove_index(options = {})
0
         @base.remove_index(@table_name, options)
0
       end
0
 
0
       # Removes the timestamp columns (created_at and updated_at) from the table.
0
- # ===== Examples
0
+ # ===== Example
0
       # t.remove_timestamps
0
       def remove_timestamps
0
         @base.remove_timestamps(@table_name)
0
@@ -592,12 +592,11 @@ module ActiveRecord
0
         @base.rename_column(@table_name, column_name, new_column_name)
0
       end
0
 
0
- # Adds a reference. Optionally adds a +type+ column. <tt>reference</tt>,
0
- # <tt>references</tt> and <tt>belongs_to</tt> are all acceptable
0
- # ===== Example
0
+ # Adds a reference. Optionally adds a +type+ column.
0
+ # <tt>references</tt> and <tt>belongs_to</tt> are acceptable.
0
+ # ===== Examples
0
       # t.references(:goat)
0
       # t.references(:goat, :polymorphic => true)
0
- # t.references(:goat)
0
       # t.belongs_to(:goat)
0
       def references(*args)
0
         options = args.extract_options!
0
@@ -609,12 +608,11 @@ module ActiveRecord
0
       end
0
       alias :belongs_to :references
0
 
0
- # Adds a reference. Optionally removes a +type+ column. <tt>remove_reference</tt>,
0
- # <tt>remove_references</tt> and <tt>remove_belongs_to</tt> are all acceptable
0
- # ===== Example
0
- # t.remove_reference(:goat)
0
- # t.remove_reference(:goat, :polymorphic => true)
0
+ # Removes a reference. Optionally removes a +type+ column.
0
+ # <tt>remove_references</tt> and <tt>remove_belongs_to</tt> are acceptable.
0
+ # ===== Examples
0
       # t.remove_references(:goat)
0
+ # t.remove_references(:goat, :polymorphic => true)
0
       # t.remove_belongs_to(:goat)
0
       def remove_references(*args)
0
         options = args.extract_options!
0
@@ -627,7 +625,7 @@ module ActiveRecord
0
       alias :remove_belongs_to :remove_references
0
 
0
       # Adds a column or columns of a specified type
0
- # ===== Example
0
+ # ===== Examples
0
       # t.string(:goat)
0
       # t.string(:goat, :sheep)
0
       %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
...
13
14
15
16
 
17
18
19
...
152
153
154
155
 
156
157
158
...
168
169
170
171
 
172
173
174
...
199
200
201
202
 
203
204
205
...
389
390
391
392
 
393
394
395
...
401
402
403
404
 
405
406
 
407
408
409
410
411
412
 
 
413
414
 
415
416
417
...
13
14
15
 
16
17
18
19
...
152
153
154
 
155
156
157
158
...
168
169
170
 
171
172
173
174
...
199
200
201
 
202
203
204
205
...
389
390
391
 
392
393
394
395
...
401
402
403
 
404
405
 
406
407
408
409
410
 
 
411
412
413
 
414
415
416
417
0
@@ -13,7 +13,7 @@ module ActiveRecord
0
         255
0
       end
0
 
0
- # Truncates a table alias according to the limits of the current adapter.
0
+ # Truncates a table alias according to the limits of the current adapter.
0
       def table_alias_for(table_name)
0
         table_name[0..table_alias_length-1].gsub(/\./, '_')
0
       end
0
@@ -152,7 +152,7 @@ module ActiveRecord
0
       # t.remove :company
0
       # end
0
       #
0
- # ====== Remove a column
0
+ # ====== Remove several columns
0
       # change_table(:suppliers) do |t|
0
       # t.remove :company_id
0
       # t.remove :width, :height
0
@@ -168,7 +168,7 @@ module ActiveRecord
0
       def change_table(table_name)
0
         yield Table.new(table_name, self)
0
       end
0
-
0
+
0
       # Renames a table.
0
       # ===== Example
0
       # rename_table('octopuses', 'octopi')
0
@@ -199,7 +199,7 @@ module ActiveRecord
0
         end
0
       end
0
       alias :remove_columns :remove_column
0
-
0
+
0
       # Changes the column's definition according to the new options.
0
       # See TableDefinition#column for details of the options you can use.
0
       # ===== Examples
0
@@ -389,7 +389,7 @@ module ActiveRecord
0
       def distinct(columns, order_by)
0
         "DISTINCT #{columns}"
0
       end
0
-
0
+
0
       # ORDER BY clause for the passed order option.
0
       # PostgreSQL overrides this due to its stricter standards compliance.
0
       def add_order_by_for_association_limiting!(sql, options)
0
@@ -401,17 +401,17 @@ module ActiveRecord
0
       # add_timestamps(:suppliers)
0
       def add_timestamps(table_name)
0
         add_column table_name, :created_at, :datetime
0
- add_column table_name, :updated_at, :datetime
0
+ add_column table_name, :updated_at, :datetime
0
       end
0
-
0
+
0
       # Removes the timestamp columns (created_at and updated_at) from the table definition.
0
       # ===== Examples
0
       # remove_timestamps(:suppliers)
0
       def remove_timestamps(table_name)
0
- remove_column table_name, :updated_at
0
- remove_column table_name, :created_at
0
+ remove_column table_name, :updated_at
0
+ remove_column table_name, :created_at
0
       end
0
-
0
+
0
       protected
0
         def options_include_default?(options)
0
           options.include?(:default) && !(options[:null] == false && options[:default].nil?)

Comments

    No one has commented yet.