Welcome to mirror list, hosted at ThFree Co, Russian Federation.

page.rb « bitbucket « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 49d083cc66f940b80cedd9fb478b1130743df59a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Bitbucket
  class Page
    attr_reader :attrs, :items

    def initialize(raw, type)
      @attrs = parse_attrs(raw)
      @items = parse_values(raw, representation_class(type))
    end

    def next?
      attrs.fetch(:next, false)
    end

    def next
      attrs.fetch(:next)
    end

    private

    def parse_attrs(raw)
      attrs = %w(size page pagelen next previous)
      attrs.map { |attr| { attr.to_sym => raw[attr] } }.reduce(&:merge)
    end

    def parse_values(raw, bitbucket_rep_class)
      return [] unless raw['values'] && raw['values'].is_a?(Array)

      raw['values'].map { |hash| bitbucket_rep_class.new(hash) }
    end

    def representation_class(type)
      Bitbucket::Representation.const_get(type.to_s.camelize)
    end
  end
end