Class: RelaxDB::PaginateParams

Inherits:
Object
  • Object
show all
Defined in:
lib/relaxdb/paginate_params.rb

Constant Summary collapse

@@params =
%w(key startkey startkey_docid endkey endkey_docid limit update descending group reduce include_docs)

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ PaginateParams

Returns a new instance of PaginateParams.



20
21
22
23
24
25
# File 'lib/relaxdb/paginate_params.rb', line 20

def initialize(params)
  params.each { |k, v| send(k, v) }
  
  # If a client hasn't explicitly set descending, set it to the CouchDB default
  @descending = false if @descending.nil?
end

Instance Method Details

#invalid?Boolean Also known as: error_msg

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/relaxdb/paginate_params.rb', line 45

def invalid?
  # Simply because allowing either to be omitted increases the complexity of the paginator
  @startkey_set && @endkey_set ? nil : "Both startkey and endkey must be set"
end

#order_inverted?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/relaxdb/paginate_params.rb', line 41

def order_inverted?
  @order_inverted
end

#update(params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/relaxdb/paginate_params.rb', line 27

def update(params)
  @order_inverted = params[:descending].nil? ? false : @descending ^ params[:descending]
  @descending = !@descending if @order_inverted

  @endkey = @startkey if @order_inverted

  @startkey = params[:startkey] || @startkey

  @skip = 1 if params[:startkey]
  
  @startkey_docid = params[:startkey_docid] if params[:startkey_docid]
  @endkey_docid = params[:endkey_docid] if params[:endkey_docid]
end