Class: CleanSweep::TableSchema::IndexSchema
- Inherits:
-
Object
- Object
- CleanSweep::TableSchema::IndexSchema
- Defined in:
- lib/clean_sweep/table_schema/index_schema.rb
Instance Attribute Summary (collapse)
-
- (Object) ascending
Returns the value of attribute ascending.
-
- (Object) columns
Returns the value of attribute columns.
-
- (Object) dest_model
Returns the value of attribute dest_model.
-
- (Object) first_only
Returns the value of attribute first_only.
-
- (Object) model
Returns the value of attribute model.
-
- (Object) name
Returns the value of attribute name.
Instance Method Summary (collapse)
-
- (Object) <<(col_name)
Add a column.
-
- (Object) add_columns_to(columns)
Take columns referenced by this index and add them to the list if they are not present.
-
- (IndexSchema) initialize(name, model, unique = false)
constructor
A new instance of IndexSchema.
- - (Object) order(scope)
- - (Object) scope_to_next_chunk(scope, last_row)
- - (Boolean) unique?
Constructor Details
- (IndexSchema) initialize(name, model, unique = false)
Returns a new instance of IndexSchema
5 6 7 8 9 10 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 5 def initialize name, model, unique = false @model = model @columns = [] @name = name @unique = unique end |
Instance Attribute Details
- (Object) ascending
Returns the value of attribute ascending
3 4 5 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 3 def ascending @ascending end |
- (Object) columns
Returns the value of attribute columns
3 4 5 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 3 def columns @columns end |
- (Object) dest_model
Returns the value of attribute dest_model
3 4 5 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 3 def dest_model @dest_model end |
- (Object) first_only
Returns the value of attribute first_only
3 4 5 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 3 def first_only @first_only end |
- (Object) model
Returns the value of attribute model
3 4 5 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 3 def model @model end |
- (Object) name
Returns the value of attribute name
3 4 5 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 3 def name @name end |
Instance Method Details
- (Object) <<(col_name)
Add a column
13 14 15 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 13 def << col_name @columns << CleanSweep::TableSchema::ColumnSchema.new(col_name, model) end |
- (Object) add_columns_to(columns)
Take columns referenced by this index and add them to the list if they are not present. Record their position in the list because the position will be where they are located in a row of values passed in later to #scope_to_next_chunk
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 24 def add_columns_to columns @columns.each do | column | pos = columns.index column if pos.nil? columns << column pos = columns.size - 1 end column.select_position = pos end end |
- (Object) order(scope)
35 36 37 38 39 40 41 42 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 35 def order(scope) direction = ascending ? 'ASC' : 'DESC' if @first_only scope.order("#{columns.first.quoted_name} #{direction}") else scope.order(columns.map { |col| "#{col.quoted_name} #{direction}"}.join(",")) end end |
- (Object) scope_to_next_chunk(scope, last_row)
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 44 def scope_to_next_chunk(scope, last_row) query_args = {} if @first_only query_args[columns.first.name] = columns.first.value(last_row) else columns.each do |column| query_args[column.name] = column.value(last_row) end end scope.where(chunk_clause, query_args) end |
- (Boolean) unique?
17 18 19 |
# File 'lib/clean_sweep/table_schema/index_schema.rb', line 17 def unique? @unique end |