class Tartarus::ArchivableCollectionRepository

Attributes

const_resolver[R]

Public Class Methods

new(const_resolver: Object) click to toggle source
# File lib/tartarus/archivable_collection_repository.rb, line 6
def initialize(const_resolver: Object)
  @const_resolver = const_resolver
end

Public Instance Methods

items_older_than(model_name, timestamp_field, timestamp) click to toggle source
# File lib/tartarus/archivable_collection_repository.rb, line 19
def items_older_than(model_name, timestamp_field, timestamp)
  collection = collection_for(model_name)
  ensure_column_exists(collection, model_name, timestamp_field)

  collection.where("#{timestamp_field} < ?", timestamp)
end
items_older_than_for_tenant(model_name, timestamp_field, timestamp, tenant_id_field, tenant_id) click to toggle source
# File lib/tartarus/archivable_collection_repository.rb, line 10
def items_older_than_for_tenant(model_name, timestamp_field, timestamp, tenant_id_field, tenant_id)
  collection = collection_for(model_name)
  ensure_column_exists(collection, model_name, timestamp_field)
  ensure_column_exists(collection, model_name, tenant_id_field)

  collection.where("#{timestamp_field} < ?", timestamp).where(tenant_id_field => tenant_id)
            .order(tenant_id_field, timestamp_field)
end

Private Instance Methods

collection_for(model_name) click to toggle source
# File lib/tartarus/archivable_collection_repository.rb, line 28
def collection_for(model_name)
  const_resolver.const_get(model_name.to_s)
end
ensure_column_exists(collection, model_name, column) click to toggle source
# File lib/tartarus/archivable_collection_repository.rb, line 32
def ensure_column_exists(collection, model_name, column)
  collection.column_names.include?(column.to_s) or raise "column :#{column} does not exist for #{model_name}"
end