Class: BitbucketServer::Collection

Inherits:
Enumerator
  • Object
show all
Defined in:
lib/bitbucket_server/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paginator) ⇒ Collection

Returns a new instance of Collection.


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bitbucket_server/collection.rb', line 9

def initialize(paginator)
  @paginator = paginator

  super() do |yielder|
    loop do
      paginator.items.each { |item| yielder << item }
    end
  end

  lazy
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/bitbucket_server/collection.rb', line 39

def method_missing(method, *args)
  return super unless self.respond_to?(method)

  self.__send__(method, *args) do |item| # rubocop:disable GitlabSecurity/PublicSend
    block_given? ? yield(item) : item
  end
end

Instance Attribute Details

#paginatorObject (readonly)

Returns the value of attribute paginator


5
6
7
# File 'lib/bitbucket_server/collection.rb', line 5

def paginator
  @paginator
end

Instance Method Details

#current_pageObject


21
22
23
24
25
# File 'lib/bitbucket_server/collection.rb', line 21

def current_page
  return 1 if page_offset <= 1

  [1, page_offset].max
end

#next_pageObject


33
34
35
36
37
# File 'lib/bitbucket_server/collection.rb', line 33

def next_page
  return unless has_next_page?

  current_page + 1
end

#prev_pageObject


27
28
29
30
31
# File 'lib/bitbucket_server/collection.rb', line 27

def prev_page
  return unless current_page > 1

  current_page - 1
end