Class: PactBroker::Pacts::Content
Class Method Summary
collapse
Instance Method Summary
collapse
call, #generate_interaction_sha
call, order_child_array, order_hash, #order_hash_keys
Constructor Details
#initialize(pact_hash) ⇒ Content
Returns a new instance of Content.
10
11
12
|
# File 'lib/pact_broker/pacts/content.rb', line 10
def initialize pact_hash
@pact_hash = pact_hash
end
|
Class Method Details
.from_hash(pact_hash) ⇒ Object
18
19
20
|
# File 'lib/pact_broker/pacts/content.rb', line 18
def self.from_hash pact_hash
new(pact_hash)
end
|
.from_json(json_content) ⇒ Object
14
15
16
|
# File 'lib/pact_broker/pacts/content.rb', line 14
def self.from_json json_content
new(Parse.call(json_content))
end
|
Instance Method Details
#content_that_affects_verification_results ⇒ Object
Half thinking this belongs in GenerateSha
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/pact_broker/pacts/content.rb', line 59
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
|
#interactions ⇒ Object
75
76
77
|
# File 'lib/pact_broker/pacts/content.rb', line 75
def interactions
pact_hash.is_a?(Hash) ? pact_hash['interactions'] : nil
end
|
#messages ⇒ Object
71
72
73
|
# File 'lib/pact_broker/pacts/content.rb', line 71
def messages
pact_hash.is_a?(Hash) ? pact_hash['messages'] : nil
end
|
#messages_or_interactions ⇒ Object
79
80
81
|
# File 'lib/pact_broker/pacts/content.rb', line 79
def messages_or_interactions
messages || interactions
end
|
#pact_specification_version ⇒ Object
83
84
85
86
87
88
|
# File 'lib/pact_broker/pacts/content.rb', line 83
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
|
#to_hash ⇒ Object
22
23
24
|
# File 'lib/pact_broker/pacts/content.rb', line 22
def to_hash
pact_hash
end
|
#to_json ⇒ Object
26
27
28
|
# File 'lib/pact_broker/pacts/content.rb', line 26
def to_json
pact_hash.to_json
end
|
#with_ids(overwrite_existing_id = true) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/pact_broker/pacts/content.rb', line 46
def with_ids(overwrite_existing_id = true)
new_pact_hash = pact_hash.dup
if interactions && interactions.is_a?(Array)
new_pact_hash['interactions'] = add_ids(interactions, overwrite_existing_id)
end
if messages && messages.is_a?(Array)
new_pact_hash['messages'] = add_ids(messages, overwrite_existing_id)
end
Content.from_hash(new_pact_hash)
end
|
#with_test_results(test_results) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/pact_broker/pacts/content.rb', line 34
def with_test_results(test_results)
new_pact_hash = pact_hash.dup
if interactions && interactions.is_a?(Array)
new_pact_hash['interactions'] = merge_verification_results(interactions, test_results)
end
if messages && messages.is_a?(Array)
new_pact_hash['messages'] = merge_verification_results(messages, test_results)
end
Content.from_hash(new_pact_hash)
end
|