class Cequel::Record::DataSetBuilder

This is a utility class to construct a {Metal::DataSet} for a given {RecordSet}.

@api private

Attributes

data_set[RW]
record_set[R]

Public Class Methods

build_for(record_set) click to toggle source

Build a data set for the given record set

@param (see initialize) @return (see build)

# File lib/cequel/record/data_set_builder.rb, line 18
def self.build_for(record_set)
  new(record_set).build
end

Private Class Methods

new(record_set) click to toggle source

@param record_set [RecordSet] record set for which to construct data

set
# File lib/cequel/record/data_set_builder.rb, line 26
def initialize(record_set)
  @record_set = record_set
  @data_set = record_set.connection[record_set.target_class.table_name]
end

Public Instance Methods

build() click to toggle source

@return [Metal::DataSet] a DataSet exposing the rows for the record set

# File lib/cequel/record/data_set_builder.rb, line 35
def build
  add_limit
  add_select_columns
  add_where_statement
  add_bounds
  add_order
  set_consistency
  set_allow_filtering
  set_page_size
  set_paging_state
  data_set
end

Private Instance Methods

add_bounds() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 79
def add_bounds
  if lower_bound
    self.data_set =
      data_set.where(*lower_bound.to_cql_with_bind_variables)
  end
  if upper_bound
    self.data_set =
      data_set.where(*upper_bound.to_cql_with_bind_variables)
  end
end
add_limit() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 61
def add_limit
  self.data_set = data_set.limit(row_limit) if row_limit
end
add_order() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 90
def add_order
  column = order_by_column
  if column.present? && reversed?
    self.data_set = data_set.order(column.name => sort_direction)
  end
end
add_select_columns() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 65
def add_select_columns
  self.data_set = data_set.select(*select_columns) if select_columns
end
add_where_statement() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 69
def add_where_statement
  if scoped_key_values
    key_conditions = Hash[scoped_key_names.zip(scoped_key_values)]
    self.data_set = data_set.where(key_conditions)
  end
  if scoped_secondary_columns
    self.data_set = data_set.where(scoped_secondary_columns)
  end
end
set_allow_filtering() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 103
def set_allow_filtering
  if allow_filtering
    self.data_set = data_set.allow_filtering!
  end
end
set_consistency() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 97
def set_consistency
  if query_consistency
    self.data_set = data_set.consistency(query_consistency)
  end
end
set_page_size() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 109
def set_page_size
  if query_page_size
    self.data_set = data_set.page_size(query_page_size)
  end
end
set_paging_state() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 115
def set_paging_state
  if query_paging_state
    self.data_set = data_set.paging_state(query_paging_state)
  end
end
sort_direction() click to toggle source
# File lib/cequel/record/data_set_builder.rb, line 121
def sort_direction
  ascends_by?(order_by_column) ? :asc : :desc
end