Class: Scheman::Schema

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

Defined Under Namespace

Classes: Field, Table

Instance Method Summary collapse

Constructor Details

#initialize(statements) ⇒ Schema

Returns a new instance of Schema.



3
4
5
# File 'lib/scheman/schema.rb', line 3

def initialize(statements)
  @statements = statements
end

Instance Method Details

#create_tablesArray<Hash>

Returns An array of CREATE TABLE statements.

Returns:

  • (Array<Hash>)

    An array of CREATE TABLE statements



12
13
14
15
16
# File 'lib/scheman/schema.rb', line 12

def create_tables
  @create_tables ||= @statements.select do |statement|
    statement[:create_table]
  end
end

#table_namesArray<String>

Returns:

  • (Array<String>)


31
32
33
# File 'lib/scheman/schema.rb', line 31

def table_names
  tables.map(&:name)
end

#tablesArray<Scheman::Schema::Table>

Returns All tables to be created after applying this schema.

Returns:



24
25
26
27
28
# File 'lib/scheman/schema.rb', line 24

def tables
  @tables ||= create_tables.map do |create_table|
    Table.new(create_table[:create_table])
  end
end

#tables_indexed_by_nameHash

Returns:

  • (Hash)


19
20
21
# File 'lib/scheman/schema.rb', line 19

def tables_indexed_by_name
  @tables_indexed_by_name ||= tables.index_by(&:name)
end

#to_hashObject



7
8
9
# File 'lib/scheman/schema.rb', line 7

def to_hash
  @statements
end