Class: PactBroker::Pacts::Selector

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Selector

Returns a new instance of Selector.



4
5
6
# File 'lib/pact_broker/pacts/selector.rb', line 4

def initialize(options = {})
  merge!(options)
end

Class Method Details

.all_for_tag(tag) ⇒ Object



48
49
50
# File 'lib/pact_broker/pacts/selector.rb', line 48

def self.all_for_tag(tag)
  Selector.new(tag: tag)
end

.all_for_tag_and_consumer(tag, consumer) ⇒ Object



52
53
54
# File 'lib/pact_broker/pacts/selector.rb', line 52

def self.all_for_tag_and_consumer(tag, consumer)
  Selector.new(tag: tag, consumer: consumer)
end

.from_hash(hash) ⇒ Object



56
57
58
# File 'lib/pact_broker/pacts/selector.rb', line 56

def self.from_hash hash
  Selector.new(hash)
end

.latest_for_tag(tag) ⇒ Object



40
41
42
# File 'lib/pact_broker/pacts/selector.rb', line 40

def self.latest_for_tag(tag)
  Selector.new(latest: true, tag: tag)
end

.latest_for_tag_with_fallback(tag, fallback_tag) ⇒ Object



44
45
46
# File 'lib/pact_broker/pacts/selector.rb', line 44

def self.latest_for_tag_with_fallback(tag, fallback_tag)
  Selector.new(latest: true, tag: tag, fallback_tag: fallback_tag)
end

.overall_latestObject



36
37
38
# File 'lib/pact_broker/pacts/selector.rb', line 36

def self.overall_latest
  Selector.new(latest: true)
end

Instance Method Details

#<=>(other) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/pact_broker/pacts/selector.rb', line 89

def <=> other
  if overall_latest? || other.overall_latest?
    if overall_latest? == other.overall_latest?
      0
    else
      overall_latest? ? -1 : 1
    end
  elsif latest_for_tag? || other.latest_for_tag?
    if latest_for_tag? == other.latest_for_tag?
      tag <=> other.tag
    else
      latest_for_tag? ? -1 : 1
    end
  elsif consumer || other.consumer
    if consumer == other.consumer
      tag <=> other.tag
    else
      consumer ? -1 : 1
    end
  else
    tag <=> other.tag
  end
end

#all_for_tag?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/pact_broker/pacts/selector.rb', line 85

def all_for_tag?
  !!(tag && !latest?)
end

#all_for_tag_and_consumer?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/pact_broker/pacts/selector.rb', line 81

def all_for_tag_and_consumer?
  !!(tag && !latest? && consumer)
end

#consumerObject



32
33
34
# File 'lib/pact_broker/pacts/selector.rb', line 32

def consumer
  self[:consumer]
end

#consumer=(consumer) ⇒ Object



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

def consumer= consumer
  self[:consumer] = consumer
end

#fallback_tagObject



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

def fallback_tag
  self[:fallback_tag]
end

#fallback_tag=(fallback_tag) ⇒ Object



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

def fallback_tag= fallback_tag
  self[:fallback_tag] = fallback_tag
end

#fallback_tag?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/pact_broker/pacts/selector.rb', line 60

def fallback_tag?
  !!fallback_tag
end

#latestObject



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

def latest
  self[:latest]
end

#latest=(latest) ⇒ Object



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

def latest= latest
  self[:latest] = latest
end

#latest_for_tag?(potential_tag = nil) ⇒ Boolean

Not sure if the fallback_tag logic is needed

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'lib/pact_broker/pacts/selector.rb', line 73

def latest_for_tag? potential_tag = nil
  if potential_tag
    !!(latest && tag == potential_tag)
  else
    !!(latest && !!tag)
  end
end

#overall_latest?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/pact_broker/pacts/selector.rb', line 68

def overall_latest?
  !!(latest? && !tag)
end

#tagObject



64
65
66
# File 'lib/pact_broker/pacts/selector.rb', line 64

def tag
  self[:tag]
end

#tag=(tag) ⇒ Object



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

def tag= tag
  self[:tag] = tag
end