Module: ActiveRecord::Acts::Versioned::ActMethods::ClassMethods
- Defined in:
- lib/acts_as_versioned.rb
Instance Method Summary collapse
-
#create_versioned_table(create_table_options = {}) ⇒ Object
Rake migration task to create the versioned table using options passed to acts_as_versioned.
-
#drop_versioned_table ⇒ Object
Rake migration task to drop the versioned table.
-
#versioned_class ⇒ Object
Returns an instance of the dynamic versioned model.
-
#versioned_columns ⇒ Object
Returns an array of columns that are versioned.
-
#without_locking(&block) ⇒ Object
Turns off optimistic locking for the duration of the block.
-
#without_revision(&block) ⇒ Object
Executes the block with the versioning callbacks disabled.
Instance Method Details
#create_versioned_table(create_table_options = {}) ⇒ Object
Rake migration task to create the versioned table using options passed to acts_as_versioned
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/acts_as_versioned.rb', line 407 def create_versioned_table( = {}) # create version column in main table if it does not exist if !self.content_columns.find { |c| [version_column.to_s, 'lock_version'].include? c.name } self.connection.add_column table_name, version_column, :integer self.reset_column_information end return if connection.table_exists?(versioned_table_name) self.connection.create_table(versioned_table_name, ) do |t| t.column versioned_foreign_key, :integer t.column version_column, :integer end self.versioned_columns.each do |col| self.connection.add_column versioned_table_name, col.name, col.type, :limit => col.limit, :default => col.default, :scale => col.scale, :precision => col.precision end if type_col = self.columns_hash[inheritance_column] self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type, :limit => type_col.limit, :default => type_col.default, :scale => type_col.scale, :precision => type_col.precision end self.connection.add_index versioned_table_name, versioned_foreign_key end |
#drop_versioned_table ⇒ Object
Rake migration task to drop the versioned table
441 442 443 |
# File 'lib/acts_as_versioned.rb', line 441 def drop_versioned_table self.connection.drop_table versioned_table_name end |
#versioned_class ⇒ Object
Returns an instance of the dynamic versioned model
402 403 404 |
# File 'lib/acts_as_versioned.rb', line 402 def versioned_class const_get versioned_class_name end |
#versioned_columns ⇒ Object
Returns an array of columns that are versioned. See non_versioned_columns
397 398 399 |
# File 'lib/acts_as_versioned.rb', line 397 def versioned_columns @versioned_columns ||= columns.select { |c| !non_versioned_columns.include?(c.name) } end |
#without_locking(&block) ⇒ Object
Turns off optimistic locking for the duration of the block
Foo.without_locking do
@foo.save
end
473 474 475 476 477 478 479 480 481 |
# File 'lib/acts_as_versioned.rb', line 473 def without_locking(&block) current = ActiveRecord::Base.lock_optimistically ActiveRecord::Base.lock_optimistically = false if current begin block.call ensure ActiveRecord::Base.lock_optimistically = true if current end end |
#without_revision(&block) ⇒ Object
Executes the block with the versioning callbacks disabled.
Foo.without_revision do
@foo.save
end
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/acts_as_versioned.rb', line 451 def without_revision(&block) class_eval do CALLBACKS.each do |attr_name| alias_method "orig_#{attr_name}".to_sym, attr_name alias_method attr_name, :empty_callback end end block.call ensure class_eval do CALLBACKS.each do |attr_name| alias_method attr_name, "orig_#{attr_name}".to_sym end end end |