Class: MotionRecord::Schema::MigrationDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/motion_record/schema/migration_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, name = nil) ⇒ MigrationDefinition

Returns a new instance of MigrationDefinition.



7
8
9
10
11
# File 'lib/motion_record/schema/migration_definition.rb', line 7

def initialize(version, name = nil)
  @version = version.to_i
  @name = name || "Migration ##{@version}"
  @definitions = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/motion_record/schema/migration_definition.rb', line 5

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



4
5
6
# File 'lib/motion_record/schema/migration_definition.rb', line 4

def version
  @version
end

Instance Method Details

#add_index(name, columns, options = {}) ⇒ Object



27
28
29
# File 'lib/motion_record/schema/migration_definition.rb', line 27

def add_index(name, columns, options = {})
  @definitions << IndexDefinition.new(name, columns, options)
end

#create_table(name, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/motion_record/schema/migration_definition.rb', line 17

def create_table(name, options = {})
  table_definition = TableDefinition.new(name, options)

  if block_given?
    yield table_definition
  end

  @definitions << table_definition
end

#executeObject



13
14
15
# File 'lib/motion_record/schema/migration_definition.rb', line 13

def execute
  @definitions.each(&:execute)
end