Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract iterator method in AR::SchemaDumper #16297

Merged
merged 1 commit into from Jul 28, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions activerecord/lib/active_record/schema_dumper.rb
Expand Up @@ -92,16 +92,9 @@ def extensions(stream)

def tables(stream)
sorted_tables = @connection.tables.sort
sorted_tables.each do |tbl|
next if ['schema_migrations', ignore_tables].flatten.any? do |ignored|
case ignored
when String; remove_prefix_and_suffix(tbl) == ignored
when Regexp; remove_prefix_and_suffix(tbl) =~ ignored
else
raise StandardError, 'ActiveRecord::SchemaDumper.ignore_tables accepts an array of String and / or Regexp values.'
end
end
table(tbl, stream)

sorted_tables.each do |table_name|
table(table_name, stream) unless ignored?(table_name)
end

# dump foreign keys at the end to make sure all dependent tables exist.
Expand Down Expand Up @@ -254,5 +247,16 @@ def foreign_keys(table, stream)
def remove_prefix_and_suffix(table)
table.gsub(/^(#{@options[:table_name_prefix]})(.+)(#{@options[:table_name_suffix]})$/, "\\2")
end

def ignored?(table_name)
['schema_migrations', ignore_tables].flatten.any? do |ignored|
case ignored
when String; remove_prefix_and_suffix(table_name) == ignored
when Regexp; remove_prefix_and_suffix(table_name) =~ ignored
else
raise StandardError, 'ActiveRecord::SchemaDumper.ignore_tables accepts an array of String and / or Regexp values.'
end
end
end
end
end