Class: Heresy::Schema
- Inherits:
-
Object
- Object
- Heresy::Schema
- Defined in:
- lib/heresy/schema.rb,
lib/heresy/schema/column.rb,
lib/heresy/schema/fields.rb
Overview
This class is responsible for defining and creating the table used to store model data.
Defined Under Namespace
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#create ⇒ Object
Creates the model table.
-
#drop ⇒ Object
Drops the model table.
-
#exists? ⇒ Boolean
Checks whether the model table exists or not.
-
#initialize(db, name) ⇒ Schema
constructor
A new instance of Schema.
- #inspect ⇒ Object
-
#to_sql ⇒ Object
Returns an array of the SQL statements used to create the table and any indexes.
Constructor Details
#initialize(db, name) ⇒ Schema
Returns a new instance of Schema.
7 8 9 10 11 12 13 14 |
# File 'lib/heresy/schema.rb', line 7 def initialize(db, name) @db = db @name = name @id = Column.new(:id, :int, :size => 11, :unsigned => true) @uuid = Column.new(:uuid, :uuid, :unique => true) @updated_at = Column.new(:updated_at, :timestamp, :default => 'CURRENT_TIMESTAMP'.lit, :index => true) @body = Column.new(:body, :blob) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/heresy/schema.rb', line 5 def body @body end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/heresy/schema.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/heresy/schema.rb', line 4 def name @name end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
5 6 7 |
# File 'lib/heresy/schema.rb', line 5 def updated_at @updated_at end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
5 6 7 |
# File 'lib/heresy/schema.rb', line 5 def uuid @uuid end |
Instance Method Details
#create ⇒ Object
Creates the model table.
22 23 24 |
# File 'lib/heresy/schema.rb', line 22 def create to_sql.each { |sql| @db.execute_ddl(sql) } end |
#drop ⇒ Object
Drops the model table.
27 28 29 |
# File 'lib/heresy/schema.rb', line 27 def drop @db.drop_table @name end |
#exists? ⇒ Boolean
Checks whether the model table exists or not.
17 18 19 |
# File 'lib/heresy/schema.rb', line 17 def exists? @db.table_exists?(@name) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/heresy/schema.rb', line 36 def inspect "<Heresy::Schema:#{@name}>" end |
#to_sql ⇒ Object
Returns an array of the SQL statements used to create the table and any indexes.
32 33 34 |
# File 'lib/heresy/schema.rb', line 32 def to_sql @db.create_table_sql_list @name, *generate.create_info end |