Module: MigrationComments

Defined in:
lib/migration_comments.rb,
lib/migration_comments/version.rb,
lib/migration_comments/annotate_models.rb,
lib/migration_comments/schema_formatter.rb

Defined Under Namespace

Modules: ActiveRecord, AnnotateModels, SchemaFormatter

Constant Summary collapse

VERSION =
"0.4.1"

Class Method Summary collapse

Class Method Details

.setupObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/migration_comments.rb', line 18

def self.setup

  base_names = %w(SchemaDumper) +
      %w(AbstractAdapter AbstractAdapter::SchemaCreation AlterTable ColumnDefinition Column Table TableDefinition).map{|name| "ConnectionAdapters::#{name}"}

  base_names.each do |base_name|
    ar_class = "ActiveRecord::#{base_name}".constantize
    mc_class = "MigrationComments::ActiveRecord::#{base_name}".constantize
    unless ar_class.descendants.include?(mc_class)
      ar_class.prepend mc_class
    end
  end

  adapters = %w(PostgreSQL Mysql2 SQLite3)
  adapters.each do |adapter|
    begin
      require("active_record/connection_adapters/#{adapter.downcase}_adapter")
      adapter_class = ('::ActiveRecord::ConnectionAdapters::' << "#{adapter}Adapter").constantize
      mc_class = ('MigrationComments::ActiveRecord::ConnectionAdapters::' << "#{adapter}Adapter").constantize
      unless adapter_class.descendants.include?(mc_class)
        adapter_class.prepend mc_class
      end
    rescue Exception => ex
    end
  end

  # annotations are not required for this gem, but if they exist they should be updated
  begin
    require 'annotate/annotate_models'
    gem_class = ::AnnotateModels
    require 'migration_comments/annotate_models'
    mc_class = MigrationComments::AnnotateModels
    unless gem_class.ancestors.include?(mc_class)
      gem_class.prepend mc_class
    end
  rescue Exception => ex
    # if we got here, don't bother installing comments into annotations
  end
end