Class Opensteam::Helper::ConfigurableTable::Column
In: lib/opensteam/helper/configurable_table.rb
Parent: Object

Methods

new   sql_query   table_name  

Attributes

config_table  [RW] 
id  [RW] 
method  [RW] 
name  [RW] 
opts  [RW] 
order  [RW] 
sql_query  [RW] 
table_name  [RW] 

Public Class methods

initialize a column if column is an association of the current model, the entries are sorted either by a ruby-block (if a :method is defined to call on the association-object), by :size (ruby-block, if its a has_many association) or simply by the id (ORDER-SQL statement) if columns is not an association, the entries are sorted by an ORDER-SQL statement.

[Source]

     # File lib/opensteam/helper/configurable_table.rb, line 160
160:         def initialize( id, config_table, *args )
161:           @id = id
162:           @opts = *args || Hash.new(nil)
163:           @method = @opts[:method]
164:           @name = @opts[:name] || @id.to_s
165:           @config_table = config_table
166:           
167:           @assoc = @config_table.assocs.find { |s| s.name.to_sym == @id.to_sym }
168:           
169:           @order = @opts[:sort]
170:          
171:           
172:           
173:           unless @order
174:             if is_assoc?
175:               if @method
176:                 @order = Proc.new { |a,b|
177:                   a.__send__( @id ).__send__( @method ).to_s <=> b.__send__( @id ).__send__( @method ).to_s
178:                 }
179:                 # @order = "`#{assoc_table_name}`.`#{@method}`"
180:               else
181:                 @order = is_has_many_assoc? ? Proc.new { |a,b| a.__send__(@method).size <=> b.__send__(@method).size } :
182:                   "`#{assoc_table_name}`.`id`"
183:               end
184:             else
185:               @order = "`#{@config_table.model.table_name}`.`#{@id}`"
186:             end
187:           end
188: 
189:         end

Public Instance methods

[Source]

     # File lib/opensteam/helper/configurable_table.rb, line 191
191:         def sql_query
192:           is_assoc? ? "`#{table_name}`.`#{@method =~ /size/ ? 'id' : @method}`" : 
193:             "`#{table_name}`.`#{@id}`" ;
194:         end

[Source]

     # File lib/opensteam/helper/configurable_table.rb, line 196
196:         def table_name
197:           is_assoc? ? assoc_table_name : @config_table.model.table_name ;
198:         end

[Validate]