Class: Migsupo::Schema::TableDefinition
- Inherits:
-
Object
- Object
- Migsupo::Schema::TableDefinition
- Defined in:
- lib/migsupo/schema/table_definition.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#indexes ⇒ Object
readonly
Returns the value of attribute indexes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #column(col_name) ⇒ Object
- #index(idx_name) ⇒ Object
-
#initialize(name:, columns: [], indexes: [], options: {}) ⇒ TableDefinition
constructor
A new instance of TableDefinition.
- #to_h ⇒ Object
Constructor Details
#initialize(name:, columns: [], indexes: [], options: {}) ⇒ TableDefinition
Returns a new instance of TableDefinition.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/migsupo/schema/table_definition.rb', line 6 def initialize(name:, columns: [], indexes: [], options: {}) @name = name.to_s @columns = columns.freeze @indexes = indexes.freeze @options = .transform_keys(&:to_sym).freeze @columns_by_name = columns.each_with_object({}) { |c, h| h[c.name] = c }.freeze @indexes_by_name = indexes.each_with_object({}) { |i, h| h[i.name] = i }.freeze freeze end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/migsupo/schema/table_definition.rb', line 4 def columns @columns end |
#indexes ⇒ Object (readonly)
Returns the value of attribute indexes.
4 5 6 |
# File 'lib/migsupo/schema/table_definition.rb', line 4 def indexes @indexes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/migsupo/schema/table_definition.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/migsupo/schema/table_definition.rb', line 4 def @options end |
Instance Method Details
#column(col_name) ⇒ Object
18 19 20 |
# File 'lib/migsupo/schema/table_definition.rb', line 18 def column(col_name) @columns_by_name[col_name.to_s] end |
#index(idx_name) ⇒ Object
22 23 24 |
# File 'lib/migsupo/schema/table_definition.rb', line 22 def index(idx_name) @indexes_by_name[idx_name.to_s] end |
#to_h ⇒ Object
26 27 28 |
# File 'lib/migsupo/schema/table_definition.rb', line 26 def to_h { name: name, columns: columns.map(&:to_h), indexes: indexes.map(&:to_h), options: } end |