Module ActiveRecord::Acts::Versioned::ActMethods::ClassMethods
In: lib/acts_as_versioned.rb

Methods

Public Instance methods

Rake migration task to create the versioned table using options passed to acts_as_versioned

[Source]

     # File lib/acts_as_versioned.rb, line 358
358:           def create_versioned_table(create_table_options = {})
359:             # create version column in main table if it does not exist
360:             if !self.content_columns.find { |c| %w(version lock_version).include? c.name }
361:               self.connection.add_column table_name, :version, :integer
362:             end
363:             
364:             self.connection.create_table(versioned_table_name, create_table_options) do |t|
365:               t.column versioned_foreign_key, :integer
366:               t.column :version, :integer
367:             end
368:             
369:             updated_col = nil
370:             self.versioned_columns.each do |col| 
371:               updated_col = col if !updated_col and %(updated_at updated_on).include?(col.name)
372:               self.connection.add_column versioned_table_name, col.name, col.type, 
373:                 :limit => col.limit, 
374:                 :default => col.default
375:             end
376:         
377:             if type_col = self.columns_hash[inheritance_column]
378:               self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type, 
379:                 :limit => type_col.limit, 
380:                 :default => type_col.default
381:             end
382:     
383:             if updated_col.nil?
384:               self.connection.add_column versioned_table_name, :updated_at, :timestamp
385:             end
386:           end

Rake migration task to drop the versioned table

[Source]

     # File lib/acts_as_versioned.rb, line 389
389:           def drop_versioned_table
390:             self.connection.drop_table versioned_table_name
391:           end

Finds a specific version of a specific row of this model

[Source]

     # File lib/acts_as_versioned.rb, line 329
329:           def find_version(id, version)
330:             find_versions(id, 
331:               :conditions => ["#{versioned_foreign_key} = ? AND version = ?", id, version], 
332:               :limit => 1).first
333:           end

Finds versions of a specific model. Takes an options hash like find

[Source]

     # File lib/acts_as_versioned.rb, line 336
336:           def find_versions(id, options = {})
337:             versioned_class.find :all, {
338:               :conditions => ["#{versioned_foreign_key} = ?", id],
339:               :order      => 'version' }.merge(options)
340:           end

An array of fields that are not saved in the versioned table

[Source]

     # File lib/acts_as_versioned.rb, line 353
353:           def non_versioned_fields
354:             [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column]
355:           end

Returns an instance of the dynamic versioned model

[Source]

     # File lib/acts_as_versioned.rb, line 348
348:           def versioned_class
349:             "ActiveRecord::Acts::Versioned::#{versioned_class_name}".constantize
350:           end

Returns an array of columns that are versioned. See non_versioned_fields

[Source]

     # File lib/acts_as_versioned.rb, line 343
343:           def versioned_columns
344:             self.columns.select { |c| !non_versioned_fields.include?(c.name) }
345:           end

[Validate]