Class: DumpCleaner::Config
- Inherits:
-
Object
- Object
- DumpCleaner::Config
show all
- Defined in:
- lib/dump_cleaner/config.rb
Defined Under Namespace
Classes: CleanupTableConfig, ConfigurationError
Constant Summary
collapse
- CleanupTableColumnConfig =
Data.define(:name, :cleanup_type, :unique) do
alias_method :unique_column?, :unique
end
- CleanupStepConfig =
Data.define(:step, :params)
- ConditionConfig =
Data.define(:column, :condition, :value)
Instance Method Summary
collapse
Constructor Details
#initialize(config_file) ⇒ Config
Returns a new instance of Config.
17
18
19
20
21
22
23
|
# File 'lib/dump_cleaner/config.rb', line 17
def initialize(config_file)
@config = load(config_file) || {}
@steps_for = {}
@keep_same_conditions = {}
set_log_level
end
|
Instance Method Details
#cleanup_table_config(db:, table:) ⇒ Object
50
51
52
|
# File 'lib/dump_cleaner/config.rb', line 50
def cleanup_table_config(db:, table:)
cleanup_table_configs.find { _1.db == db && _1.table == table }
end
|
#cleanup_tables ⇒ Object
46
47
48
|
# File 'lib/dump_cleaner/config.rb', line 46
def cleanup_tables
cleanup_table_configs.map { [_1.db, _1.table] }
end
|
25
26
27
|
# File 'lib/dump_cleaner/config.rb', line 25
def dump_format
@config.dig("dump", "format")
end
|
#ignore_keep_same_record_conditions?(type) ⇒ Boolean
42
43
44
|
# File 'lib/dump_cleaner/config.rb', line 42
def ignore_keep_same_record_conditions?(type)
cleanup_config_for(type)["ignore_keep_same_record_conditions"] == true
end
|
#keep_same_conditions(type) ⇒ Object
36
37
38
39
40
|
# File 'lib/dump_cleaner/config.rb', line 36
def keep_same_conditions(type)
@keep_same_conditions[type] ||= Array(cleanup_config_for(type)["keep_same_conditions"]).map do
ConditionConfig.new(condition: _1["condition"], value: _1["value"], column: nil)
end
end
|
#steps_for(type, phase) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/dump_cleaner/config.rb', line 29
def steps_for(type, phase)
@steps_for[type] ||= {}
@steps_for[type][phase.to_s] ||= Array(cleanup_config_for(type)[phase.to_s]).map do
CleanupStepConfig.new(step: _1["step"], params: (_1["params"] || {}).transform_keys(&:to_sym))
end
end
|