Class: PactBroker::Pacts::VerifiablePact

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pact, selectors, pending = nil, pending_provider_tags = [], non_pending_provider_tags = [], provider_branch = nil, wip = false) ⇒ VerifiablePact

rubocop: disable Metrics/ParameterLists TODO refactor this constructor



11
12
13
14
15
16
17
18
19
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 11

def initialize(pact, selectors, pending = nil, pending_provider_tags = [], non_pending_provider_tags = [], provider_branch = nil, wip = false)
  super(pact)
  @pending = pending
  @selectors = selectors
  @pending_provider_tags = pending_provider_tags
  @non_pending_provider_tags = non_pending_provider_tags
  @provider_branch = provider_branch
  @wip = wip
end

Instance Attribute Details

#non_pending_provider_tagsObject (readonly)

Returns the value of attribute non_pending_provider_tags.



7
8
9
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 7

def non_pending_provider_tags
  @non_pending_provider_tags
end

#pendingObject (readonly)

Returns the value of attribute pending.



7
8
9
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 7

def pending
  @pending
end

#pending_provider_tagsObject (readonly)

Returns the value of attribute pending_provider_tags.



7
8
9
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 7

def pending_provider_tags
  @pending_provider_tags
end

#provider_branchObject (readonly)

Returns the value of attribute provider_branch.



7
8
9
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 7

def provider_branch
  @provider_branch
end

#selectorsObject (readonly)

Returns the value of attribute selectors.



7
8
9
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 7

def selectors
  @selectors
end

#wipObject (readonly)

Returns the value of attribute wip.



7
8
9
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 7

def wip
  @wip
end

Class Method Details

.create_for_wip_for_provider_branch(pact, selectors, provider_branch) ⇒ Object

rubocop: enable Metrics/ParameterLists



22
23
24
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 22

def self.create_for_wip_for_provider_branch(pact, selectors, provider_branch)
  new(pact, selectors, true, [], [], provider_branch, true)
end

.create_for_wip_for_provider_tags(pact, selectors, pending_provider_tags) ⇒ Object



26
27
28
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 26

def self.create_for_wip_for_provider_tags(pact, selectors, pending_provider_tags)
  new(pact, selectors, true, pending_provider_tags, [], nil, true)
end

.deduplicate(verifiable_pacts) ⇒ Object



30
31
32
33
34
35
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 30

def self.deduplicate(verifiable_pacts)
  verifiable_pacts
    .group_by { | verifiable_pact | [verifiable_pact.consumer_name, verifiable_pact.pact_version_sha] }
    .values
    .collect { | verifiable_pact | verifiable_pact.reduce(&:+) }
end

Instance Method Details

#+(other) ⇒ Object



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
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 45

def + other
  if pact_version_sha != other.pact_version_sha
    raise PactBroker::Error.new("Can't merge two verifiable pacts with different pact content")
  end

  if provider_branch != other.provider_branch
    raise PactBroker::Error.new("Can't merge two verifiable pacts with different provider_branch")
  end

  if consumer_name != other.consumer_name
    raise PactBroker::Error.new("Can't merge two verifiable pacts with different consumer names")
  end

  latest_pact = [self, other].sort_by(&:consumer_version_order).last.__getobj__()

  VerifiablePact.new(
    latest_pact,
    selectors + other.selectors,
    pending || other.pending,
    pending_provider_tags + other.pending_provider_tags,
    non_pending_provider_tags + other.non_pending_provider_tags,
    provider_branch,
    wip || other.wip
  )
end

#<=>(other) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 71

def <=> other
  if self.consumer_name != other.consumer_name
    return self.consumer_name <=> other.consumer_name
  else
    return self.consumer_version.order <=> other.consumer_version.order
  end
end

#consumer_version_orderObject



79
80
81
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 79

def consumer_version_order
  __getobj__().consumer_version.order
end

#pending?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 37

def pending?
  pending
end

#wip?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 41

def wip?
  wip
end