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.
133 134 135 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 133 def initialize(table_info) @table_info = table_info end |
Class Method Details
.load(db:, table:, source_dump_path:) ⇒ Object
123 124 125 126 127 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 123 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
129 130 131 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 129 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
165 166 167 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 165 def column_index(name) columns.index(name) end |
#columns ⇒ Object
161 162 163 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 161 def columns @columns ||= @table_info.dig("options", "columns") end |
#compression ⇒ Object
153 154 155 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 153 def compression @table_info["compression"] end |
#db ⇒ Object
137 138 139 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 137 def db @db ||= @table_info.dig("options", "schema") end |
#db_at_table ⇒ Object
149 150 151 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 149 def db_at_table "#{db}@#{table}" end |
#db_dot_table ⇒ Object
145 146 147 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 145 def db_dot_table "#{db}.#{table}" end |
#dialect ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 169 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
157 158 159 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 157 def extension @table_info["extension"] end |
#table ⇒ Object
141 142 143 |
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 141 def table @table ||= @table_info.dig("options", "table") end |