Class: Edgestitch::Exporter
- Inherits:
-
Object
- Object
- Edgestitch::Exporter
- Defined in:
- lib/edgestitch/exporter.rb
Overview
This class is responsible for exporting an engine’s owned tables and migrations to a SQL file.
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Class Method Summary collapse
-
.export(engine, dump) ⇒ Object
Exports an engine using a dump helper (@see Edgestitch::Mysql::Dump).
Instance Method Summary collapse
- #export(dump, to: structure_file_path) ⇒ Object
-
#initialize(engine) ⇒ Exporter
constructor
A new instance of Exporter.
- #migrations ⇒ Object
- #tables ⇒ Object
Constructor Details
#initialize(engine) ⇒ Exporter
Returns a new instance of Exporter.
21 22 23 24 25 26 |
# File 'lib/edgestitch/exporter.rb', line 21 def initialize(engine) @engine = engine @database_directory_path = engine.root.join("db") @extra_tables_path = database_directory_path.join("extra_tables") @structure_file_path = database_directory_path.join("structure-self.sql") end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
19 20 21 |
# File 'lib/edgestitch/exporter.rb', line 19 def engine @engine end |
Class Method Details
.export(engine, dump) ⇒ Object
Exports an engine using a dump helper (@see Edgestitch::Mysql::Dump)
15 16 17 |
# File 'lib/edgestitch/exporter.rb', line 15 def self.export(engine, dump) new(engine).export(dump) end |
Instance Method Details
#export(dump, to: structure_file_path) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/edgestitch/exporter.rb', line 28 def export(dump, to: structure_file_path) StringIO.open do |buffer| buffer.puts dump.export_tables(tables) buffer.puts buffer.puts dump.export_migrations(migrations) File.write to, "#{buffer.string.strip}\n" end end |
#migrations ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/edgestitch/exporter.rb', line 37 def migrations @migrations ||= begin migrations_glob = database_directory_path.join("{migrate,migrate.archive}/*.rb") Dir[migrations_glob] .map { |filename| File.basename(filename).to_i } .sort end end |
#tables ⇒ Object
46 47 48 |
# File 'lib/edgestitch/exporter.rb', line 46 def tables component_tables + extra_tables end |