Class: Partitioned::PartitionedBase::Configurator::Reader
- Inherits:
-
Object
- Object
- Partitioned::PartitionedBase::Configurator::Reader
- Defined in:
- lib/partitioned/partitioned_base/configurator/reader.rb
Overview
coalesces and parses all Data objects allowing the PartitionManager to request partitioning information froma centralized source.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#base_name(*partition_key_values) ⇒ Object
The name of the child table without the schema name or name prefix.
-
#check_constraint(*partition_key_values) ⇒ Object
Define the check constraint for a given child table.
-
#foreign_keys(*partition_key_values) ⇒ Object
Define a foreign key on a (leaf-) child table.
-
#indexes(*partition_key_values) ⇒ Object
Define an index to be created on all (leaf-) child tables.
-
#initialize(most_derived_activerecord_class) ⇒ Reader
constructor
A new instance of Reader.
- #janitorial_archives_needed ⇒ Object
- #janitorial_creates_needed ⇒ Object
- #janitorial_drops_needed ⇒ Object
-
#last_partitions_order_by_clause ⇒ Object
Define the order by clause used to list all child table names in order of “last to be used” to “oldest to have been used”.
-
#name_prefix ⇒ Object
The prefix for the child table’s name.
-
#on_fields ⇒ Object
The field used to partition child tables.
-
#parent_table_name(*partition_key_values) ⇒ Object
The table name of the table who is the direct ancestor of a child table.
-
#parent_table_schema_name(*partition_key_values) ⇒ Object
The schema name of the table who is the direct ancestor of a child table.
-
#part_name(*partition_key_values) ⇒ Object
The child tables name without the schema name.
- #run_after_partition_table_create_hooks(*partition_key_values) ⇒ Object
-
#schema_name ⇒ Object
The name of the schema that will contain all child tables.
-
#table_alias_name(*partition_key_values) ⇒ Object
A reasonable alias for this partition table.
-
#table_name(*partition_key_values) ⇒ Object
The full name of a child table defined by the partition key values.
Constructor Details
#initialize(most_derived_activerecord_class) ⇒ Reader
Returns a new instance of Reader.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 10 def initialize(most_derived_activerecord_class) @model = most_derived_activerecord_class @configurators = nil @on_fields = nil @indexes = nil @foreign_keys = nil @check_constraint = nil @schema_name = nil @name_prefix = nil @base_name = nil @part_name = nil @table_name = nil @parent_table_schema_name = nil @parent_table_name = nil @encoded_name = nil @janitorial_creates_needed = nil @janitorial_archives_needed = nil @janitorial_drops_needed = nil @after_partition_table_create_hooks = nil end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 8 def model @model end |
Instance Method Details
#base_name(*partition_key_values) ⇒ Object
The name of the child table without the schema name or name prefix.
122 123 124 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 122 def base_name(*partition_key_values) return collect_first(*partition_key_values, &:base_name) end |
#check_constraint(*partition_key_values) ⇒ Object
Define the check constraint for a given child table.
83 84 85 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 83 def check_constraint(*partition_key_values) return collect_first(*partition_key_values, &:check_constraint) end |
#foreign_keys(*partition_key_values) ⇒ Object
Define a foreign key on a (leaf-) child table.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 69 def foreign_keys(*partition_key_values) return collect_from_collection(*partition_key_values, &:foreign_keys).inject(Set.new) do |set,new_items| if new_items.is_a? Array set += new_items else set += [new_items] end set end end |
#indexes(*partition_key_values) ⇒ Object
Define an index to be created on all (leaf-) child tables.
59 60 61 62 63 64 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 59 def indexes(*partition_key_values) return collect_from_collection(*partition_key_values, &:indexes).inject({}) do |bag, data_index| bag[data_index.field] = (data_index. || {}) unless data_index.blank? bag end end |
#janitorial_archives_needed ⇒ Object
161 162 163 164 165 166 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 161 def janitorial_archives_needed unless @janitorial_archives_needed @janitorial_archives_needed = collect_first(&:janitorial_archives_needed) end return @janitorial_archives_needed end |
#janitorial_creates_needed ⇒ Object
154 155 156 157 158 159 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 154 def janitorial_creates_needed unless @janitorial_creates_needed @janitorial_creates_needed = collect_first(&:janitorial_creates_needed) end return @janitorial_creates_needed end |
#janitorial_drops_needed ⇒ Object
168 169 170 171 172 173 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 168 def janitorial_drops_needed unless @janitorial_drops_needed @janitorial_drops_needed = collect_first(&:janitorial_drops_needed) end return @janitorial_drops_needed end |
#last_partitions_order_by_clause ⇒ Object
Define the order by clause used to list all child table names in order of “last to be used” to “oldest to have been used”.
147 148 149 150 151 152 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 147 def last_partitions_order_by_clause unless @last_partitions_order_by_clause @last_partitions_order_by_clause = collect_first(&:last_partitions_order_by_clause) end return @last_partitions_order_by_clause end |
#name_prefix ⇒ Object
The prefix for the child table’s name.
129 130 131 132 133 134 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 129 def name_prefix unless @name_prefix @name_prefix = collect_first(&:name_prefix) end return @name_prefix end |
#on_fields ⇒ Object
The field used to partition child tables.
49 50 51 52 53 54 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 49 def on_fields unless @on_fields @on_fields = collect(&:on_field).map(&:to_sym) end return @on_fields end |
#parent_table_name(*partition_key_values) ⇒ Object
The table name of the table who is the direct ancestor of a child table.
90 91 92 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 90 def parent_table_name(*partition_key_values) return collect_first(*partition_key_values, &:parent_table_name) end |
#parent_table_schema_name(*partition_key_values) ⇒ Object
The schema name of the table who is the direct ancestor of a child table.
97 98 99 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 97 def parent_table_schema_name(*partition_key_values) return collect_first(*partition_key_values, &:parent_table_schema_name) end |
#part_name(*partition_key_values) ⇒ Object
The child tables name without the schema name.
139 140 141 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 139 def part_name(*partition_key_values) return collect_first(*partition_key_values, &:part_name) end |
#run_after_partition_table_create_hooks(*partition_key_values) ⇒ Object
175 176 177 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 175 def run_after_partition_table_create_hooks(*partition_key_values) collect_from_collection(*partition_key_values, &:after_partition_table_create_hooks) end |
#schema_name ⇒ Object
The name of the schema that will contain all child tables.
39 40 41 42 43 44 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 39 def schema_name unless @schema_name @schema_name = collect_first(&:schema_name) end return @schema_name end |
#table_alias_name(*partition_key_values) ⇒ Object
A reasonable alias for this partition table
115 116 117 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 115 def table_alias_name(*partition_key_values) return collect_first(*partition_key_values, &:table_alias_name) end |
#table_name(*partition_key_values) ⇒ Object
The full name of a child table defined by the partition key values.
104 105 106 107 108 109 110 |
# File 'lib/partitioned/partitioned_base/configurator/reader.rb', line 104 def table_name(*partition_key_values) if partition_key_values.length < 1 return model.table_name else return collect_first(*partition_key_values, &:table_name) end end |