Class: Miguel::Schema::Table::Context
- Inherits:
-
Object
- Object
- Miguel::Schema::Table::Context
- Defined in:
- lib/miguel/schema.rb
Overview
Helper class used to evaluate the +add_table+ block. Also implements the timestamping helper.
Instance Method Summary collapse
-
#initialize(table) ⇒ Context
constructor
Create new context for given table.
-
#method_missing(name, *args) ⇒ Object
Send anything unrecognized as new definition to our table.
-
#timestamps ⇒ Object
Create the default timestamp fields.
Constructor Details
#initialize(table) ⇒ Context
Create new context for given table.
294 295 296 |
# File 'lib/miguel/schema.rb', line 294 def initialize( table ) @table = table end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Send anything unrecognized as new definition to our table.
299 300 301 |
# File 'lib/miguel/schema.rb', line 299 def method_missing( name, *args ) @table.add_definition( name, *args ) end |
Instance Method Details
#timestamps ⇒ Object
Create the default timestamp fields.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/miguel/schema.rb', line 310 def opts = @table.schema.opts if opts[ :mysql_timestamps ] # Unfortunately, MySQL allows only either automatic create timestamp # (DEFAULT CURRENT_TIMESTAMP) or automatic update timestamp (DEFAULT # CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP), but not both - one # has to be updated manually anyway. So we choose to have the update timestamp # automatically updated, and let the create one to be set manually. # Also, Sequel doesn't currently honor :on_update for column definitions, # so we have to use default literal to make it work. Sigh. :create_time, :null => false, :default => ZERO_TIME :update_time, :null => false, :default => Sequel.lit( 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP' ) else Time :create_time Time :update_time end end |