Class: DumpCleaner::Cleaners::MysqlShellTableCleaner::DumpTableInfo
- Inherits:
-
Object
- Object
- DumpCleaner::Cleaners::MysqlShellTableCleaner::DumpTableInfo
- Defined in:
- lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb
Constant Summary collapse
- DialectOptions =
Data.define(:lines_terminated_by, :fields_terminated_by, :fields_enclosed_by, :fields_optionally_enclosed, :fields_escaped_by)
Class Method Summary collapse
- .load(db:, table:, source_dump_path:) ⇒ Object
- .table_info_file_path(db:, table:, source_dump_path:) ⇒ Object
Instance Method Summary collapse
- #column_index(name) ⇒ Object
- #columns ⇒ Object
- #compression ⇒ Object
- #db ⇒ Object
- #db_at_table ⇒ Object
- #db_dot_table ⇒ Object
- #dialect ⇒ Object
- #extension ⇒ Object
-
#initialize(table_info) ⇒ DumpTableInfo
constructor
A new instance of DumpTableInfo.
- #table ⇒ Object
Constructor Details
#initialize(table_info) ⇒ DumpTableInfo
Returns a new instance of DumpTableInfo.
134 135 136 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 134 def initialize(table_info) @table_info = table_info end |
Class Method Details
.load(db:, table:, source_dump_path:) ⇒ Object
124 125 126 127 128 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 124 def self.load(db:, table:, source_dump_path:) new(JSON.parse(File.read(table_info_file_path(db:, table:, source_dump_path:)))) rescue Errno::ENOENT raise "Table info file not found in dump for table '#{db}.#{table}'. Is the table included in the dump?" end |
.table_info_file_path(db:, table:, source_dump_path:) ⇒ Object
130 131 132 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 130 def self.table_info_file_path(db:, table:, source_dump_path:) "#{source_dump_path}/#{db}@#{table}.json" end |
Instance Method Details
#column_index(name) ⇒ Object
166 167 168 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 166 def column_index(name) columns.index(name) end |
#columns ⇒ Object
162 163 164 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 162 def columns @columns ||= @table_info.dig("options", "columns") end |
#compression ⇒ Object
154 155 156 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 154 def compression @table_info["compression"] end |
#db ⇒ Object
138 139 140 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 138 def db @db ||= @table_info.dig("options", "schema") end |
#db_at_table ⇒ Object
150 151 152 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 150 def db_at_table "#{db}@#{table}" end |
#db_dot_table ⇒ Object
146 147 148 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 146 def db_dot_table "#{db}.#{table}" end |
#dialect ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 170 def dialect @dialect ||= begin = DialectOptions.members.each_with_object({}) do |option, | lowercase_option = option.to_s.split("_").each_with_object([]) do |e, buffer| buffer.push(buffer.empty? ? e : e.capitalize) end.join [option] = @table_info.dig("options", lowercase_option) end DialectOptions.new(**) end end |
#extension ⇒ Object
158 159 160 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 158 def extension @table_info["extension"] end |
#table ⇒ Object
142 143 144 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 142 def table @table ||= @table_info.dig("options", "table") end |