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



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

def initialize(statements)
  @statements = statements
end

Instance Method Details

#create_tablesArray<Hash>



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>



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

def table_names
  tables.map(&:name)
end

#tablesArray<Scheman::Schema::Table>



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



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