Class: Ridgepole::Dumper
- Inherits:
-
Object
- Object
- Ridgepole::Dumper
- Defined in:
- lib/ridgepole/dumper.rb
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(options = {}) ⇒ Dumper
constructor
A new instance of Dumper.
Constructor Details
#initialize(options = {}) ⇒ Dumper
Returns a new instance of Dumper.
2 3 4 |
# File 'lib/ridgepole/dumper.rb', line 2 def initialize( = {}) @options = end |
Instance Method Details
#dump ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ridgepole/dumper.rb', line 6 def dump stream = StringIO.new conn = ActiveRecord::Base.connection target_tables = @options.fetch(:tables, []) unless target_tables.empty? conn.tables.each do |tbl| next if target_tables.include?(tbl) ActiveRecord::SchemaDumper.ignore_tables << tbl end end ActiveRecord::SchemaDumper.dump(conn, stream) dsl = stream.string.lines.select {|line| line !~ /\A#/ && line !~ /\AActiveRecord::Schema\.define/ && line !~ /\Aend/ }.join.undent.strip definitions = [] each_table(dsl) do |name, definition| if target?(name) definitions << definition yield(name, definition) if block_given? end end definitions.join("\n\n") end |