Class: DbSubsetter::Exporter
- Inherits:
-
Object
- Object
- DbSubsetter::Exporter
- Defined in:
- lib/db_subsetter/exporter.rb
Instance Attribute Summary collapse
-
#filter ⇒ Object
writeonly
Sets the attribute filter.
Instance Method Summary collapse
- #all_tables ⇒ Object
- #export(filename) ⇒ Object
- #filtered_row_counts ⇒ Object
- #tables ⇒ Object
- #total_row_counts ⇒ Object
- #verify_exportability ⇒ Object
Instance Attribute Details
#filter=(value) ⇒ Object
Sets the attribute filter
5 6 7 |
# File 'lib/db_subsetter/exporter.rb', line 5 def filter=(value) @filter = value end |
Instance Method Details
#all_tables ⇒ Object
7 8 9 |
# File 'lib/db_subsetter/exporter.rb', line 7 def all_tables ActiveRecord::Base.connection.tables end |
#export(filename) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/db_subsetter/exporter.rb', line 35 def export(filename) verify_exportability @output = SQLite3::Database.new(filename) @output.execute("CREATE TABLE tables (name TEXT, records_exported INTEGER, columns TEXT)") tables.each do |table| export_table(table) end end |
#filtered_row_counts ⇒ Object
23 24 25 26 27 |
# File 'lib/db_subsetter/exporter.rb', line 23 def filtered_row_counts tables.each.map do |table| {table => filtered_row_count(table)} end end |
#tables ⇒ Object
11 12 13 |
# File 'lib/db_subsetter/exporter.rb', line 11 def tables filter.tables end |
#total_row_counts ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/db_subsetter/exporter.rb', line 15 def total_row_counts tables.each.map do |table| query = Arel::Table.new(table, ActiveRecord::Base).project("count(1) AS num_rows") rows = ActiveRecord::Base.connection.select_one(query.to_sql)["num_rows"] {table => rows} end end |
#verify_exportability ⇒ Object
29 30 31 32 33 |
# File 'lib/db_subsetter/exporter.rb', line 29 def verify_exportability tables.each do |table| verify_table_exportability(table) end end |