Method: ActiveRecord::Base.declare

Defined in:
lib/rmtools/active_record/declarative.rb

.declare(name, options = {}, &block) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/rmtools/active_record/declarative.rb', line 134

def declare(name, options={}, &block)
  self.table_name = name
  if !table_exists? or options[:force]
    $log < "with options[:force] the `#{table_name}` table will have been recreated each time you load the #{model_name} model" if options[:force]
    self.primary_key = options[:primary_key] if options[:id] != false and options[:primary_key]
    $log.debug "connection.create_table(#{name}, #{options.inspect}) {}"
    connection.create_table(name, options, &block)
  elsif options[:map]
    table = ConnectionAdapters::VirtualTable.new(name, connection, options[:map])
    yield table
    table.map!
  else yield ConnectionAdapters::VirtualTable.new(name, connection)
  end
  reset_column_information
end