Module: PartitionGardener::Registry
- Defined in:
- lib/partition_gardener/registry.rb
Class Method Summary collapse
- .configs_for_table(table_name) ⇒ Object
- .each_table_config(&block) ⇒ Object
- .expanded_table_configs ⇒ Object
- .find_by_table_name(table_name) ⇒ Object
- .hot_switch_partition_config(table_name) ⇒ Object
- .map(&block) ⇒ Object
- .register(config) ⇒ Object
- .register_all(configs) ⇒ Object
- .register_template(template_name, **options) ⇒ Object
- .reset! ⇒ Object
- .tables ⇒ Object
-
.TABLES ⇒ Object
Prefer
.tables.
Class Method Details
.configs_for_table(table_name) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/partition_gardener/registry.rb', line 32 def configs_for_table(table_name) name = table_name.to_s registered = tables.find { |config| config[:table_name].to_s == name } return Templates.(registered) if registered&.fetch(:layout, nil) == :composite .select do |config| config[:table_name].to_s == name || config[:parent_table_name].to_s == name end end |
.each_table_config(&block) ⇒ Object
24 25 26 |
# File 'lib/partition_gardener/registry.rb', line 24 def each_table_config(&block) .each(&block) end |
.expanded_table_configs ⇒ Object
28 29 30 |
# File 'lib/partition_gardener/registry.rb', line 28 def end |
.find_by_table_name(table_name) ⇒ Object
42 43 44 |
# File 'lib/partition_gardener/registry.rb', line 42 def find_by_table_name(table_name) .find { |config| config[:table_name].to_s == table_name.to_s } end |
.hot_switch_partition_config(table_name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/partition_gardener/registry.rb', line 46 def hot_switch_partition_config(table_name) config = find_by_table_name(table_name) return nil unless config { table_name: config[:table_name], partition_name_format: config[:partition_name_format], partition_definition: config[:partition_definition], partitions_to_create: lambda { |today| [DateCalendar.beginning_of_month(today), DateCalendar.beginning_of_month(DateCalendar.next_month(today))] } } end |
.map(&block) ⇒ Object
64 65 66 |
# File 'lib/partition_gardener/registry.rb', line 64 def map(&block) each_table_config.map(&block) end |
.register(config) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/partition_gardener/registry.rb', line 4 def register(config) normalized = Templates.normalize(config) normalized[:maintenance_backend] = MaintenanceBackend.normalize(normalized[:maintenance_backend]) tables.delete_if { |entry| entry[:table_name] == normalized[:table_name] } tables << normalized MaintenanceBackend.validate!(normalized) normalized end |
.register_all(configs) ⇒ Object
20 21 22 |
# File 'lib/partition_gardener/registry.rb', line 20 def register_all(configs) configs.map { |config| register(config) } end |
.register_template(template_name, **options) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/partition_gardener/registry.rb', line 13 def register_template(template_name, **) builder = Templates.public_method(template_name) register(builder.call(**)) rescue NameError raise ArgumentError, "unknown template: #{template_name.inspect}" end |
.reset! ⇒ Object
73 74 75 |
# File 'lib/partition_gardener/registry.rb', line 73 def reset! @tables = [] end |
.tables ⇒ Object
60 61 62 |
# File 'lib/partition_gardener/registry.rb', line 60 def tables @tables ||= [] end |
.TABLES ⇒ Object
Prefer .tables. Kept for callers that used the old constant name.
69 70 71 |
# File 'lib/partition_gardener/registry.rb', line 69 def self.TABLES tables end |