2018-07-25 08:22:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-25 16:06:10 -04:00
|
|
|
module BitbucketServer
|
|
|
|
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(:isLastPage, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def next
|
|
|
|
attrs.fetch(:nextPageStart)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parse_attrs(raw)
|
2018-08-01 13:44:45 -04:00
|
|
|
raw.slice('size', 'nextPageStart', 'isLastPage').symbolize_keys
|
2018-06-25 16:06:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse_values(raw, bitbucket_rep_class)
|
|
|
|
return [] unless raw['values'] && raw['values'].is_a?(Array)
|
|
|
|
|
|
|
|
bitbucket_rep_class.decorate(raw['values'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def representation_class(type)
|
2019-10-15 23:06:12 -04:00
|
|
|
BitbucketServer::Representation.const_get(type.to_s.camelize, false)
|
2018-06-25 16:06:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|