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

TODO refactor this constructor



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

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



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

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



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

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



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

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

Instance Method Details

#+(other) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 43

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

  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



65
66
67
68
69
70
71
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 65

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



73
74
75
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 73

def consumer_version_order
  __getobj__().consumer_version.order
end

#pending?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 35

def pending?
  pending
end

#wip?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/pact_broker/pacts/verifiable_pact.rb', line 39

def wip?
  wip
end