class ActiveRedis::QueryChainer

Attributes

aggregation_options[R]
limit_options[R]
order_options[R]
target[R]
where_options[R]

Public Class Methods

new(target) click to toggle source
# File lib/active_redis/query_chainer.rb, line 14
def initialize(target)
  @where_options = {}
  @order_options = {id: :asc}
  @limit_options = {}
  @aggregation_options = {}
  @target = target
end

Public Instance Methods

apply_all(options) click to toggle source
# File lib/active_redis/query_chainer.rb, line 41
def apply_all(options)
  apply_limit Hash.new
end
apply_first(options) click to toggle source
# File lib/active_redis/query_chainer.rb, line 37
def apply_first(options)
  apply_limit per_page: 1, page: 0
end
apply_limit(options) click to toggle source
# File lib/active_redis/query_chainer.rb, line 32
def apply_limit(options)
  @limit_options = options
  self
end
apply_order(options) click to toggle source
# File lib/active_redis/query_chainer.rb, line 27
def apply_order(options)
  @order_options = options if options.any?
  self
end
apply_where(options) click to toggle source
# File lib/active_redis/query_chainer.rb, line 22
def apply_where(options)
  @where_options.merge!(options)
  self
end
linked_objects() click to toggle source
# File lib/active_redis/query_chainer.rb, line 55
def linked_objects
  @collection ||= objects_by_query
end
reload() click to toggle source
# File lib/active_redis/query_chainer.rb, line 51
def reload
  @collection = nil
end

Private Instance Methods

apply_aggregation(type, field) click to toggle source
# File lib/active_redis/query_chainer.rb, line 61
def apply_aggregation(type, field)
  @aggregation_options = {type => field}
  execute_query
end
execute_query() click to toggle source
# File lib/active_redis/query_chainer.rb, line 66
def execute_query
  QueryExecutor.execute self
end
first_limit?() click to toggle source
# File lib/active_redis/query_chainer.rb, line 75
def first_limit?
  @limit_options[:per_page] == 1 && @limit_options[:page] == 0
end
objects_by_query() click to toggle source
# File lib/active_redis/query_chainer.rb, line 70
def objects_by_query
  res = execute_query.inject([]) { |arr, attrs| arr << @target.new(attrs) if attrs && attrs.any?; arr }
  first_limit? ? res.first : res
end