2018-10-06 23:10:08 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-22 18:48:31 +00:00
|
|
|
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)
|
2016-12-07 12:00:06 +00:00
|
|
|
raw.slice(*%w(size page pagelen next previous)).symbolize_keys
|
2016-08-22 18:48:31 +00:00
|
|
|
end
|
|
|
|
|
2016-11-22 04:49:40 +00:00
|
|
|
def parse_values(raw, bitbucket_rep_class)
|
2016-11-21 16:25:47 +00:00
|
|
|
return [] unless raw['values'] && raw['values'].is_a?(Array)
|
2016-12-12 15:29:25 +00:00
|
|
|
|
2016-12-07 12:00:06 +00:00
|
|
|
bitbucket_rep_class.decorate(raw['values'])
|
2016-08-22 18:48:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def representation_class(type)
|
2019-10-16 03:06:12 +00:00
|
|
|
Bitbucket::Representation.const_get(type.to_s.camelize, false)
|
2016-08-22 18:48:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|