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



56
57
58
# File 'lib/pact_broker/api/resources/latest_pact.rb', line 56

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

#pactObject



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

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

#policy_recordObject



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

def policy_record
  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



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

def to_extended_json
  PactBroker::Api::Decorators::ExtendedPactDecorator.new(pact).to_json(user_options: decorator_context(metadata: ))
end

#to_htmlObject



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

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

#to_jsonObject



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

def to_json
  response.headers['X-Pact-Consumer-Version'] = pact.consumer_version_number
  PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(user_options: decorator_context(metadata: ))
end