Class: JobIteration::ActiveRecordBatchEnumerator::ColumnManager
- Inherits:
-
Object
- Object
- JobIteration::ActiveRecordBatchEnumerator::ColumnManager
- Defined in:
- lib/job-iteration/active_record_batch_enumerator/column_manager.rb
Overview
Utility class for the batch enumerator that manages the columns that need to be plucked. It ensures primary key columns are plucked so that records in the batch can be queried for efficiently.
Instance Attribute Summary collapse
-
#columns ⇒ Array<String>
readonly
The list of columns to be plucked.
-
#pluck_columns ⇒ Array<String>
readonly
The full set of columns to be plucked from the relation.
-
#primary_key ⇒ Array<String>
readonly
The list of primary key columns for the relation.
Instance Method Summary collapse
-
#initialize(relation:, columns:) ⇒ ColumnManager
constructor
A new instance of ColumnManager.
-
#pkey_values(column_values) ⇒ Array<Array>
List where each item contains the primary key column values for the corresponding row.
-
#remove_missing_pkey_values(cursor) ⇒ Array
The same values that were passed in, minus any primary key column values that do not appear in
columns.
Constructor Details
#initialize(relation:, columns:) ⇒ ColumnManager
Returns a new instance of ColumnManager.
13 14 15 16 17 18 19 20 21 |
# File 'lib/job-iteration/active_record_batch_enumerator/column_manager.rb', line 13 def initialize(relation:, columns:) @table_name = relation.table_name @primary_key = Array(relation.primary_key) @qualified_pkey_columns = @primary_key.map { |col| qualify_column(col) } @columns = columns&.map(&:to_s) || @qualified_pkey_columns validate_columns!(relation) initialize_pluck_columns_and_pkey_positions end |
Instance Attribute Details
#columns ⇒ Array<String> (readonly)
Returns The list of columns to be plucked. If no columns were specified, this list contains the fully qualified primary key column(s).
26 27 28 |
# File 'lib/job-iteration/active_record_batch_enumerator/column_manager.rb', line 26 def columns @columns end |
#pluck_columns ⇒ Array<String> (readonly)
Returns The full set of columns to be plucked from the relation. This is a superset of columns and is guaranteed to contain all of the primary key columns on the relation.
37 38 39 |
# File 'lib/job-iteration/active_record_batch_enumerator/column_manager.rb', line 37 def pluck_columns @pluck_columns end |
#primary_key ⇒ Array<String> (readonly)
Returns The list of primary key columns for the relation. These columns are not qualified with the table name.
31 32 33 |
# File 'lib/job-iteration/active_record_batch_enumerator/column_manager.rb', line 31 def primary_key @primary_key end |
Instance Method Details
#pkey_values(column_values) ⇒ Array<Array>
Returns List where each item contains the primary key column values for the corresponding row. Values are guaranteed to be in the same order as the columns are listed in primary_key.
47 48 49 50 51 52 53 54 |
# File 'lib/job-iteration/active_record_batch_enumerator/column_manager.rb', line 47 def pkey_values(column_values) column_values.map do |values| @qualified_pkey_columns.map do |pkey_column| pkey_column_idx = @primary_key_index_map[pkey_column] values[pkey_column_idx] end end end |
#remove_missing_pkey_values(cursor) ⇒ Array
Returns The same values that were passed in, minus any primary key column values that do not appear in columns.
62 63 64 65 |
# File 'lib/job-iteration/active_record_batch_enumerator/column_manager.rb', line 62 def remove_missing_pkey_values(cursor) cursor.pop(@missing_pkey_count) cursor end |