Class: WithModel::Table
- Inherits:
-
Object
- Object
- WithModel::Table
- Defined in:
- lib/with_model/table.rb
Overview
In general, direct use of this class should be avoided. Instead use either the high-level API or low-level API.
Instance Method Summary collapse
-
#create ⇒ Object
Creates the table with the initialized options.
- #destroy ⇒ Object
-
#initialize(name, options = {}, connection: ActiveRecord::Base.connection, &block) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(name, options = {}, connection: ActiveRecord::Base.connection, &block) ⇒ Table
Returns a new instance of Table.
14 15 16 17 18 19 |
# File 'lib/with_model/table.rb', line 14 def initialize(name, = {}, connection: ActiveRecord::Base.connection, &block) @name = name.freeze @options = .freeze @block = block @connection = connection end |
Instance Method Details
#create ⇒ Object
Creates the table with the initialized options. Drops the table if it already exists.
23 24 25 26 |
# File 'lib/with_model/table.rb', line 23 def create connection.drop_table(@name) if exists? connection.create_table(@name, **@options, &@block) end |
#destroy ⇒ Object
28 29 30 |
# File 'lib/with_model/table.rb', line 28 def destroy connection.drop_table(@name) end |