Class: CMIS::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/cmis/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository, statement, options = {}) ⇒ Query

Options: from, page_size



7
8
9
10
11
12
13
14
15
# File 'lib/cmis/query.rb', line 7

def initialize(repository, statement, options = {})
  @repository = repository
  @statement = statement
  @options = options.symbolize_keys

  @total = -1

  init_options
end

Instance Method Details

#each_page(options = {}, &block) ⇒ Object

Options: limit



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cmis/query.rb', line 36

def each_page(options = {}, &block)
  return enum_for(:each_page, options) unless block_given?

  init_options
  limit = parse_limit(options)
  counter = 0

  while has_next?
    break unless counter < limit
    yield r = results
    counter += r.size
  end
end

#each_result(options = {}, &block) ⇒ Object

Options: limit



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cmis/query.rb', line 18

def each_result(options = {}, &block)
  return enum_for(:each_result, options) unless block_given?

  init_options
  limit = parse_limit(options)
  return if limit == 0

  counter = 0
  while has_next?
    results.each do |object|
      yield object
      counter = counter.next
      return unless counter < limit
    end
  end
end

#has_next?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/cmis/query.rb', line 60

def has_next?
  @has_next
end

#resultsObject



50
51
52
53
54
55
56
57
58
# File 'lib/cmis/query.rb', line 50

def results
  result = do_query

  @skip_count += result.results.size
  @has_next = result.has_more_items
  @total = result.num_items

  result.results
end

#totalObject



64
65
66
67
# File 'lib/cmis/query.rb', line 64

def total
  # CMIS AWS trickery
  @total = @total == -1 ? do_query.num_items : @total
end