lib/arid_cache/cache_proxy/result_processor.rb
def filter_results(records, apply_order=true)
        return records if order_in_database?

        # Order
        if apply_order && records.respond_to?(:sort)
          if @options.order_by_proc?
            records = records.sort(&@options[:order])
          elsif @options.order_by_key? && is_hashes?
            records = records.sort do |a, b|
              a[@options[:order]] <=> b[@options[:order]]
            end
          end
        end

        # Limit / Offset
        if (@options.include?(:offset) || @options.include?(:limit)) && records.respond_to?(:[])
          begin
            records = records[@options[:offset] || 0, @options[:limit] || records.size]
          rescue ArgumentError
            raise ArgumentError.new("Cannot apply limit or offset to #{records.class} #{records.inspect}")
          end
          records = [] if records.nil? # out-of-range offset returns nil
        end

        # Paginate
        if @options.paginate? && records.respond_to?(:paginate)
          # Convert records to an array before calling paginate.  If we don't do this
          # and the result is a named scope, paginate will trigger an additional query
          # to load the page rather than just using the records we have already fetched.
          records = records.respond_to?(:to_a) ? records.to_a : records
          records = records.paginate(@options.opts_for_paginate(records))
        end
        records
      end
# Return the result after processing it to apply limits or pagination in memory.
# Doesn't do anything if we have to order in the databse.
#
# Options are only applied if the object responds to the appropriate method.
# So for example pagination will not happen unless the object responds to :paginate.
#
# Options:
#   :order  - Ordering is done first, before applying limits or paginating.
#             If it's a Proc it is passed to Array#sort to do the sorting.
#             If it is a Symbol or String the results should be Hashes and the
#             list of Hashes are sorted by the values at the given key.
#   :limit  - limit the array to the specified size
#   :offset - ignore the first +offset+ items in the array
#   :page / :per_page - paginate the result.  If :limit is specified, the array is
#             limited before paginating; similarly if :offset is specified the array is offset
#             before paginating.  Pagination only happens if the :page option is passed.
#
# == Arguments
# * records - array of records to process.  Could be ids, ActiveRecords or any other
#   objects.
# * apply_order - boolean, default true.  If true and the collection responds to sort,
#   then apply the sort, which is usually by proc or key.  If false, no reordering is done.
Return the result after processing it to apply limits or pagination in memory.
Doesn't do anything if we have to order in the databse.

Options are only applied if the object responds to the appropriate method.
So for example pagination will not happen unless the object responds to :paginate.

:order  - Ordering is done first, before applying limits or paginating.
If it's a Proc it is passed to Array#sort to do the sorting.
If it is a Symbol or String the results should be Hashes and the
list of Hashes are sorted by the values at the given key.
:limit  - limit the array to the specified size
:offset - ignore the first +offset+ items in the array
:page / :per_page - paginate the result.  If :limit is specified, the array is
limited before paginating; similarly if :offset is specified the array is offset
before paginating.  Pagination only happens if the :page option is passed.

Arguments
records - array of records to process.  Could be ids, ActiveRecords or any other
objects.
apply_order - boolean, default true.  If true and the collection responds to sort,
then apply the sort, which is usually by proc or key.  If false, no reordering is done.
Return the result after processing it to apply limits or pagination in memory . Doesn ' t do anything if we have to order in the databse . Options are only applied if the object responds to the appropriate method . So for example pagination will not happen unless the object responds to : paginate . : order - Ordering is done first before applying limits or paginating . If it ' s a Proc it is passed to Array#sort to do the sorting . If it is a Symbol or String the results should be Hashes and the list of Hashes are sorted by the values at the given key . : limit - limit the array to the specified size : offset - ignore the first + offset + items in the array : page / : per_page - paginate the result . If : limit is specified the array is limited before paginating ; similarly if : offset is specified the array is offset before paginating . Pagination only happens if the : page option is passed . Arguments records - array of records to process . Could be ids ActiveRecords or any other objects . apply_order - boolean default true . If true and the collection responds to sort then apply the sort which is usually by proc or key . If false no reordering is done .
def filter_results(records, apply_order=true)
        return records if order_in_database?
        if apply_order && records.respond_to?(:sort)
          if @options.order_by_proc?
            records = records.sort(&@options[:order])
          elsif @options.order_by_key? && is_hashes?
            records = records.sort do |a, b|
              a[@options[:order]] <=> b[@options[:order]]
            end
          end
        end
        if (@options.include?(:offset) || @options.include?(:limit)) && records.respond_to?(:[])
          begin
            records = records[@options[:offset] || 0, @options[:limit] || records.size]
          rescue ArgumentError
            raise ArgumentError.new("Cannot apply limit or offset to #{records.class} #{records.inspect}")
          end
          records = [] if records.nil? 
        end
        if @options.paginate? && records.respond_to?(:paginate)
          records = records.respond_to?(:to_a) ? records.to_a : records
          records = records.paginate(@options.opts_for_paginate(records))
        end
        records
      end
def filter_results ( records , apply_order = true ) return records if order_in_database? if apply_order && records . respond_to? ( :sort ) if @options . order_by_proc? records = records . sort ( & @options [ :order ] ) elsif @options . order_by_key? && is_hashes? records = records . sort do | a , b | a [ @options [ :order ] ] <=> b [ @options [ :order ] ] end end end if ( @options . include? ( :offset ) || @options . include? ( :limit ) ) && records . respond_to? ( :[] ) begin records = records [ @options [ :offset ] || 0 , @options [ :limit ] || records . size ] rescue ArgumentError raise ArgumentError . new ( "Cannot apply limit or offset to #{records.class} #{records.inspect}" ) end records = [ ] if records . nil? end if @options . paginate? && records . respond_to? ( :paginate ) records = records . respond_to? ( :to_a ) ? records . to_a : records records = records . paginate ( @options . opts_for_paginate ( records ) ) end records end
Return the result after processing it to apply limits or pagination in memory.
Return the result after processing it to apply limits or pagination in memory .
# Order # Limit / Offset # out-of-range offset returns nil # Paginate # Convert records to an array before calling paginate.  If we don't do this # and the result is a named scope, paginate will trigger an additional query # to load the page rather than just using the records we have already fetched.
records
apply_order