Class: PactBroker::Pacts::Selector
- Inherits:
-
Hash
- Object
- Hash
- PactBroker::Pacts::Selector
- Defined in:
- lib/pact_broker/pacts/selector.rb
Class Method Summary collapse
- .all_for_tag(tag) ⇒ Object
- .all_for_tag_and_consumer(tag, consumer) ⇒ Object
- .from_hash(hash) ⇒ Object
- .latest_for_tag(tag) ⇒ Object
- .latest_for_tag_with_fallback(tag, fallback_tag) ⇒ Object
- .overall_latest ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #all_for_tag? ⇒ Boolean
- #all_for_tag_and_consumer? ⇒ Boolean
- #consumer ⇒ Object
- #consumer=(consumer) ⇒ Object
- #fallback_tag ⇒ Object
- #fallback_tag=(fallback_tag) ⇒ Object
- #fallback_tag? ⇒ Boolean
-
#initialize(options = {}) ⇒ Selector
constructor
A new instance of Selector.
- #latest ⇒ Object
- #latest=(latest) ⇒ Object
-
#latest_for_tag?(potential_tag = nil) ⇒ Boolean
Not sure if the fallback_tag logic is needed.
- #overall_latest? ⇒ Boolean
- #tag ⇒ Object
- #tag=(tag) ⇒ Object
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( = {}) merge!() 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 |
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
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
81 82 83 |
# File 'lib/pact_broker/pacts/selector.rb', line 81 def all_for_tag_and_consumer? !!(tag && !latest? && consumer) end |
#consumer ⇒ Object
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_tag ⇒ Object
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
60 61 62 |
# File 'lib/pact_broker/pacts/selector.rb', line 60 def fallback_tag? !!fallback_tag end |
#latest ⇒ Object
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
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
68 69 70 |
# File 'lib/pact_broker/pacts/selector.rb', line 68 def overall_latest? !!(latest? && !tag) end |
#tag ⇒ Object
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 |