Class: Scheman::Schema
- Inherits:
-
Object
- Object
- Scheman::Schema
- Defined in:
- lib/scheman/schema.rb
Defined Under Namespace
Instance Method Summary collapse
-
#create_tables ⇒ Array<Hash>
An array of CREATE TABLE statements.
-
#initialize(statements) ⇒ Schema
constructor
A new instance of Schema.
- #table_names ⇒ Array<String>
-
#tables ⇒ Array<Scheman::Schema::Table>
All tables to be created after applying this schema.
- #tables_indexed_by_name ⇒ Hash
- #to_hash ⇒ Object
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_tables ⇒ Array<Hash>
Returns 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_names ⇒ Array<String>
31 32 33 |
# File 'lib/scheman/schema.rb', line 31 def table_names tables.map(&:name) end |
#tables ⇒ Array<Scheman::Schema::Table>
Returns All tables to be created after applying this schema.
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_name ⇒ 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_hash ⇒ Object
7 8 9 |
# File 'lib/scheman/schema.rb', line 7 def to_hash @statements end |