Class Field
In: app/models/field.rb
Parent: Object

Methods

<=>   cid   default   limit   name   new   null   precision   primary   scale   sql_type   type   update  

Included Modules

Comparable Switch

Attributes

attributes  [RW] 
database  [RW] 
table  [RW] 

Public Class methods

This method assigns the database and table this field appears in, along with all the attributes, no matter how useless they may be.

[Source]

    # File app/models/field.rb, line 14
14:   def initialize( table, attributes )
15:     self.table      = table
16:     self.attributes = attributes
17:     self.database   = self.table.database
18:   end

Public Instance methods

This is our obligation to Comparable. Order by column id (which is faked for some databases).

[Source]

    # File app/models/field.rb, line 24
24:   def <=>( other ) 
25:     self.cid <=> other.cid 
26:   end

column id mapping

[Source]

    # File app/models/field.rb, line 57
57:   def cid
58:     self.attributes[:cid]
59:   end

default value mapping

[Source]

     # File app/models/field.rb, line 113
113:   def default
114:     self.attributes[:default]
115:   end

limit mapping

[Source]

    # File app/models/field.rb, line 78
78:   def limit
79:     self.attributes[:limit]
80:   end

name mapping

[Source]

    # File app/models/field.rb, line 50
50:   def name
51:     self.attributes[:name]
52:   end

is null mapping

[Source]

     # File app/models/field.rb, line 106
106:   def null
107:     self.attributes[:null]
108:   end

precision mapping

[Source]

    # File app/models/field.rb, line 85
85:   def precision
86:     self.attributes[:precision]
87:   end

inconsistant on some databases

[Source]

     # File app/models/field.rb, line 99
 99:   def primary
100:     self.attributes[:primary]
101:   end

scale mapping

[Source]

    # File app/models/field.rb, line 92
92:   def scale
93:     self.attributes[:scale]
94:   end

not all databases send this

[Source]

    # File app/models/field.rb, line 64
64:   def sql_type
65:     self.attributes[:sql_type]
66:   end

field type mapping

[Source]

    # File app/models/field.rb, line 71
71:   def type
72:     self.attributes[:type]
73:   end

Update the field using the parameters passed. This first checks the name for an update then operates on the actual field attributes.

[Source]

    # File app/models/field.rb, line 33
33:   def update( params )
34:     switch( self.database ) do
35:       if params['field'] !=  params['fields']['1']['name']
36:         ActiveRecord::Base.connection.rename_column( self.table.name.to_sym,
37:                                                      params['field'].to_sym,
38:                                                      params['fields']['1']['name'].to_sym )
39:       end
40:       ActiveRecord::Base.connection.change_column( self.table.name.to_sym,
41:                                                    params['fields']['1']['name'].to_sym,
42:                                                    params['fields']['1']['type'].to_sym,
43:                                                    mangle_column_options( params, '1' ) )
44:     end
45:   end

[Validate]