Browse files

Merge pull request #11987 from wangjohn/schema_dumper_options

Creating options for schema dumper.
  • Loading branch information...
2 parents 68d7a1e + 9f82fb3 commit eec00b8c03273d006aa12505bde32e2a2547b670 @rafaelfranca rafaelfranca committed Sep 23, 2013
Showing with 16 additions and 5 deletions.
  1. +16 −5 activerecord/lib/active_record/schema_dumper.rb
View
21 activerecord/lib/active_record/schema_dumper.rb
@@ -17,9 +17,19 @@ class SchemaDumper #:nodoc:
cattr_accessor :ignore_tables
@@ignore_tables = []
- def self.dump(connection=ActiveRecord::Base.connection, stream=STDOUT)
- new(connection).dump(stream)
- stream
+ class << self
+ def dump(connection=ActiveRecord::Base.connection, stream=STDOUT, config = ActiveRecord::Base)
+ new(connection, generate_options(config)).dump(stream)
+ stream
+ end
+
+ private
+ def generate_options(config)
+ {
+ table_name_prefix: config.table_name_prefix,
+ table_name_suffix: config.table_name_suffix
+ }
+ end
end
def dump(stream)
@@ -32,10 +42,11 @@ def dump(stream)
private
- def initialize(connection)
+ def initialize(connection, options = {})
@connection = connection
@types = @connection.native_database_types
@version = Migrator::current_version rescue nil
+ @options = options
end
def header(stream)
@@ -201,7 +212,7 @@ def indexes(table, stream)
end
def remove_prefix_and_suffix(table)
- table.gsub(/^(#{ActiveRecord::Base.table_name_prefix})(.+)(#{ActiveRecord::Base.table_name_suffix})$/, "\\2")
+ table.gsub(/^(#{@options[:table_name_prefix]})(.+)(#{@options[:table_name_suffix]})$/, "\\2")
end
end
end

0 comments on commit eec00b8

Please sign in to comment.