Class: SchemaRD::MigrationContext::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/schemard/schema_parser.rb

Defined Under Namespace

Modules: ActiveRecord Classes: TableDefinition

Instance Method Summary collapse

Constructor Details

#initialize(schema, with_comment: false) ⇒ Loader

“with_comment” must be assigned, but ruby2.0 needs default value.



53
54
55
56
# File 'lib/schemard/schema_parser.rb', line 53

def initialize(schema, with_comment: false)
  @schema = schema
  @parse_db_comment = with_comment
end

Instance Method Details

#add_index(table_name, column_name, options = {}) ⇒ Object



65
66
67
68
69
# File 'lib/schemard/schema_parser.rb', line 65

def add_index(table_name, column_name, options = {})
  column_name = [ column_name ] unless column_name.is_a?(Array)
  index = SchemaRD::TableIndex.new(options.merge({ columns: column_name }))
  @schema.table(table_name).indexes << index
end

#create_table(table_name, options = {}) {|TableDefinition.new(table, with_comment: @parse_db_comment)| ... } ⇒ Object

Yields:



57
58
59
60
61
62
63
64
# File 'lib/schemard/schema_parser.rb', line 57

def create_table(table_name, options = {})
  if options[:comment] && @parse_db_comment
    options[:parsed_db_comment] = options.delete(:comment)
  end
  table = SchemaRD::Table.new(options.merge(name: table_name))
  @schema.add_table(table_name, table)
  yield TableDefinition.new(table, with_comment: @parse_db_comment)
end

#enable_extension(*args) ⇒ Object



70
# File 'lib/schemard/schema_parser.rb', line 70

def enable_extension(*args); end