Class: ActiveRecord::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/forcast/tasks/schema/schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



17
18
19
# File 'lib/forcast/tasks/schema/schema.rb', line 17

def method_missing(*args)
  # ignore add_index, etc.
end

Class Method Details

.add_table(table_name, columns) ⇒ Object



25
26
27
28
# File 'lib/forcast/tasks/schema/schema.rb', line 25

def self.add_table(table_name, columns)
  @schema ||= {}
  @schema[table_name] = columns
end

.define(*args, &block) ⇒ Object



21
22
23
# File 'lib/forcast/tasks/schema/schema.rb', line 21

def self.define(*args, &block)
  new.instance_eval(&block)
end

.schemaObject



30
31
32
# File 'lib/forcast/tasks/schema/schema.rb', line 30

def self.schema
  @schema || {}
end

Instance Method Details

#create_table(table_name, options = {}) {|table| ... } ⇒ Object

Yields:

  • (table)


11
12
13
14
15
# File 'lib/forcast/tasks/schema/schema.rb', line 11

def create_table(table_name, options={}, &block)
  table = Table.new(table_name)
  yield table if block_given?
  self.class.add_table(table.name, table.columns)
end