/
version_decorator.rb
74 lines (62 loc) · 2.07 KB
/
version_decorator.rb
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require_relative 'base_decorator'
require_relative 'embedded_tag_decorator'
module PactBroker
module Api
module Decorators
class VersionDecorator < BaseDecorator
property :number, writeable: false
property :branch
property :build_url, as: :buildUrl
collection :tags, embedded: true, writeable: false, :extend => PactBroker::Api::Decorators::EmbeddedTagDecorator
include Timestamps
link :self do | options |
{
title: 'Version',
name: represented.number,
href: version_url(options.fetch(:base_url), represented)
}
end
link :'pb:pacticipant' do | options |
{
title: 'Pacticipant',
name: represented.pacticipant.name,
href: pacticipant_url(options.fetch(:base_url), represented.pacticipant)
}
end
link :'pb:tag' do | options |
{
href: version_url(options.fetch(:base_url), represented) + '/tags/{tag}',
title: "Get, create or delete a tag for this pacticipant version",
templated: true
}
end
link :'pb:latest-verification-results-where-pacticipant-is-consumer' do | options |
{
title: "Latest verification results for consumer version",
href: latest_verifications_for_consumer_version_url(represented, options.fetch(:base_url))
}
end
links :'pb:pact-versions' do | context |
sorted_pacts.collect do | pact |
{
title: "Pact",
name: pact.name,
href: pact_url(context[:base_url], pact),
}
end
end
curies do | options |
[{
name: :pb,
href: options.fetch(:base_url) + '/doc/{rel}?context=version',
templated: true
}]
end
private
def sorted_pacts
represented.pact_publications.sort{ |a, b| a.provider_name.downcase <=> b.provider_name.downcase }
end
end
end
end
end