Files

UbiquoI18n::Adapters::SchemaStatements

Extends the create_table method to support the :translatable option

Public Class Methods

apply_translatable_option!(method, adapter, table_name, options = {}) {|table| ...} click to toggle source

Performs the actual job of applying the :translatable option

    # File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/adapters/schema_statements.rb, line 31
31:       def self.apply_translatable_option!(method, adapter, table_name, options = {})
32:         translatable = options.delete(:translatable)
33:         method_name = "#{method}_without_translatable"
34: 
35:         # not all methods accept the options hash
36:         args = [table_name]
37:         args << options if adapter.method(method_name).arity != 1
38: 
39:         adapter.send(method_name, *args) do |table|
40:           if translatable
41:             table.string :locale, :nil => false
42:             table.sequence table_name, :content_id
43:           elsif translatable == false && method == :change_table
44:             table.remove :locale
45:             table.remove_sequence :test, :content_id
46:           end
47:           yield table
48:         end
49: 
50:         # create or remove indexes for these new fields
51:         indexes = [:locale, :content_id]
52:         if translatable
53:           indexes.each do |index|
54:             unless adapter.indexes(table_name).map(&:columns).flatten.include? index.to_s
55:               adapter.add_index table_name, index
56:             end
57:           end
58:         elsif translatable == false
59:           indexes.each do |index|
60:             if adapter.indexes(table_name).map(&:columns).flatten.include? index.to_s
61:               adapter.remove_index table_name, index
62:             end
63:           end
64:         end
65:       end
included(klass) click to toggle source

Perform the actual linking with create_table

    # File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/adapters/schema_statements.rb, line 7
 7:       def self.included(klass)
 8:         klass.send(:alias_method_chain, :create_table, :translatable)
 9:         klass.send(:alias_method_chain, :change_table, :translatable)
10:       end

Public Instance Methods

change_table_with_translatable(*args, &block) click to toggle source

Parse the :translatable option as a change_table extension This will currently add two fields:

  table.locale: string
  table.content_id sequence

with their respective indexes

    # File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/adapters/schema_statements.rb, line 26
26:       def change_table_with_translatable(*args, &block)
27:         SchemaStatements.apply_translatable_option!(:change_table, self, *args, &block)
28:       end
create_table_with_translatable(*args, &block) click to toggle source

Parse the :translatable option as a create_table extension This will currently add two fields:

  table.locale: string
  table.content_id sequence

with their respective indexes

    # File vendor/plugins/ubiquo_i18n/lib/ubiquo_i18n/adapters/schema_statements.rb, line 17
17:       def create_table_with_translatable(*args, &block)
18:         SchemaStatements.apply_translatable_option!(:create_table, self, *args, &block)
19:       end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.