Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7932 (closed enhancement: wontfix)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Add method_missing to TableDefinitions for nicer syntax

Reported by: norbert Assigned to: core
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: migration schema tiny
Cc:

Description

Here's a small patch that adds method_missing to the TableDefinitions class which is used by create_table. It allows you to rewrite this:

create_table :people do |t|
  t.column :name, :string
  t.column :age,  :integer
end

to this:

create_table :people do |t|
  t.name :string
  t.age  :integer
end

Attachments

method_missing_for_table_definitions.diff (1.3 kB) - added by norbert on 03/27/07 22:45:22.
method_missing_for_table_definitions_by_extend.diff (1.9 kB) - added by norbert on 04/03/07 16:09:30.

Change History

03/27/07 22:45:22 changed by norbert

  • attachment method_missing_for_table_definitions.diff added.

03/27/07 23:24:24 changed by court3nay

This is freakin' sweet

03/30/07 18:27:12 changed by pimpmaster

Now that's a DRY migration if I ever saw one. Someone please commit this to core ASAP!

04/03/07 16:09:30 changed by norbert

  • attachment method_missing_for_table_definitions_by_extend.diff added.

04/03/07 16:13:12 changed by norbert

Right, I meant TableDefinition and not TableDefinitions.

Anyway, here's a new patch with a slightly different approach. It keeps the actual TableDefinition class clean and only extends it with method_missing in create_table. Also, the unit test now shows this works with options too (as suggested by manfred). Enjoy!

05/08/07 08:07:28 changed by norbert

  • status changed from new to closed.
  • resolution set to wontfix.

This has become kind of redundant because of [6667].