Extends the create_table method to support the :versionable option
Performs the actual job of applying the :translatable option
# File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/adapters/schema_statements.rb, line 37
37: def self.apply_versionable_option!(method, adapter, table_name, options = {})
38: versionable = options.delete(:versionable)
39: method_name = "#{method}_without_versions"
40:
41: # not all methods accept the options hash
42: args = [table_name]
43: args << options if adapter.method(method_name).arity != 1
44:
45: adapter.send(method_name, *args) do |table|
46: if versionable
47: table.sequence table_name, :version_number
48: table.sequence table_name, :content_id
49: table.boolean :is_current_version, :null => false, :default => false
50: table.integer :parent_version
51: elsif versionable == false && method == :change_table
52: table.remove :is_current_version, :parent_version
53: table.remove_sequence :test, :version_number
54: table.remove_sequence :test, :content_id
55: end
56: yield table
57: end
58:
59: # create or remove indexes for these new fields
60: indexes = [:is_current_version, :parent_version, :content_id]
61: if versionable
62: indexes.each do |index|
63: unless adapter.indexes(table_name).map(&:columns).flatten.include? index.to_s
64: adapter.add_index table_name, index
65: end
66: end
67: elsif versionable == false
68: indexes.each do |index|
69: if adapter.indexes(table_name).map(&:columns).flatten.include? index.to_s
70: adapter.remove_index table_name, index
71: end
72: end
73: end
74:
75: end
Perform the actual linking with create_table
# File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/adapters/schema_statements.rb, line 7
7: def self.included(klass)
8: klass.send(:alias_method_chain, :create_table, :versions)
9: klass.send(:alias_method_chain, :change_table, :versions)
10: end
Parse the :versionable option as a create_table extension
This will actually add four fields:
table.version_number : sequence table.content_id : sequence table.is_current_version : boolean table.parent_version : integer
with their respective indexes (except for version_number)
# File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/adapters/schema_statements.rb, line 32
32: def change_table_with_versions(*args, &block)
33: SchemaStatements.apply_versionable_option!(:change_table, self, *args, &block)
34: end
Parse the :versionable option as a create_table extension
This will actually add four fields:
table.version_number : sequence table.content_id : sequence table.is_current_version : boolean table.parent_version : integer
with their respective indexes (except for version_number)
# File vendor/plugins/ubiquo_versions/lib/ubiquo_versions/adapters/schema_statements.rb, line 20
20: def create_table_with_versions(*args, &block)
21: SchemaStatements.apply_versionable_option!(:create_table, self, *args, &block)
22: end
Disabled; run with $DEBUG to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.