Class: PactBroker::Pacts::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/pacts/content.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pact_hash) ⇒ Content

Returns a new instance of Content.



8
9
10
# File 'lib/pact_broker/pacts/content.rb', line 8

def initialize pact_hash
  @pact_hash = pact_hash
end

Class Method Details

.from_hash(pact_hash) ⇒ Object



16
17
18
# File 'lib/pact_broker/pacts/content.rb', line 16

def self.from_hash pact_hash
  new(pact_hash)
end

.from_json(json_content) ⇒ Object



12
13
14
# File 'lib/pact_broker/pacts/content.rb', line 12

def self.from_json json_content
  new(Parse.call(json_content))
end

Instance Method Details

#content_that_affects_verification_resultsObject

Half thinking this belongs in GenerateSha



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pact_broker/pacts/content.rb', line 33

def content_that_affects_verification_results
  if interactions || messages
    cont = {}
    cont['interactions'] = interactions if interactions
    cont['messages'] = messages if messages
    cont['pact_specification_version'] = pact_specification_version if pact_specification_version
    cont
  else
    pact_hash
  end
end

#interactionsObject



49
50
51
# File 'lib/pact_broker/pacts/content.rb', line 49

def interactions
  pact_hash.is_a?(Hash) ? pact_hash['interactions'] : nil
end

#messagesObject



45
46
47
# File 'lib/pact_broker/pacts/content.rb', line 45

def messages
  pact_hash.is_a?(Hash) ? pact_hash['messages'] : nil
end

#pact_specification_versionObject



53
54
55
56
57
58
# File 'lib/pact_broker/pacts/content.rb', line 53

def pact_specification_version
  maybe_pact_specification_version_1 = pact_hash['metadata']['pactSpecification']['version'] rescue nil
  maybe_pact_specification_version_2 = pact_hash['metadata']['pact-specification']['version'] rescue nil
  maybe_pact_specification_version_3 = pact_hash['metadata'] && pact_hash['metadata']['pactSpecificationVersion'] rescue nil
  maybe_pact_specification_version_1 || maybe_pact_specification_version_2 || maybe_pact_specification_version_3
end

#sortObject



28
29
30
# File 'lib/pact_broker/pacts/content.rb', line 28

def sort
  Content.from_hash(SortContent.call(pact_hash))
end

#to_hashObject



20
21
22
# File 'lib/pact_broker/pacts/content.rb', line 20

def to_hash
  pact_hash
end

#to_jsonObject



24
25
26
# File 'lib/pact_broker/pacts/content.rb', line 24

def to_json
  pact_hash.to_json
end