Class: PactBroker::Api::Resources::LatestPact

Inherits:
BaseResource
  • Object
show all
Defined in:
lib/pact_broker/api/resources/latest_pact.rb

Instance Method Summary collapse

Instance Method Details

#allowed_methodsObject



19
20
21
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 19

def allowed_methods
  ["GET", "OPTIONS"]
end

#content_types_providedObject



10
11
12
13
14
15
16
17
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 10

def content_types_provided
  [
    ["application/hal+json", :to_json],
    ["application/json", :to_json],
    ["text/html", :to_html],
    ["application/vnd.pactbrokerextended.v1+json", :to_extended_json]
  ]
end

#metadataObject



52
53
54
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 52

def 
  @metadata ||= (PactBroker::Pacts::Metadata.(pact, identifier_from_path))
end

#pactObject



48
49
50
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 48

def pact
  @pact ||= pact_service.find_latest_pact(identifier_from_path)
end

#policy_nameObject



27
28
29
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 27

def policy_name
  :'pacts::pact'
end

#resource_exists?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 23

def resource_exists?
  !!pact
end

#to_extended_jsonObject



36
37
38
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 36

def to_extended_json
  decorator_class(:extended_pact_decorator).new(pact).to_json(decorator_options(metadata: ))
end

#to_htmlObject



40
41
42
43
44
45
46
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 40

def to_html
  PactBroker.configuration.html_pact_renderer.call(
    pact, {
      base_url: ui_base_url,
      badge_url: "#{resource_url}/badge.svg"
  })
end

#to_jsonObject



31
32
33
34
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 31

def to_json
  response.headers["X-Pact-Consumer-Version"] = pact.consumer_version_number
  decorator_class(:pact_decorator).new(pact).to_json(decorator_options(metadata: ))
end