Class: PactBroker::DB::Clean::Selector
- Inherits:
-
Object
- Object
- PactBroker::DB::Clean::Selector
- Defined in:
- lib/pact_broker/db/clean/selector.rb
Constant Summary collapse
- ATTRIBUTES =
[:pacticipant_name, :latest, :tag, :branch, :environment_name, :max_age, :deployed, :released, :main_branch]
Class Method Summary collapse
Instance Method Summary collapse
- #currently_deployed? ⇒ Boolean
- #currently_supported? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Selector
constructor
A new instance of Selector.
- #latest? ⇒ Boolean
- #to_hash ⇒ Object (also: #to_h)
- #to_json(_opts = nil) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Selector
Returns a new instance of Selector.
13 14 15 16 17 18 |
# File 'lib/pact_broker/db/clean/selector.rb', line 13 def initialize(attributes = {}) attributes.each do | (name, value) | instance_variable_set("@#{name}", value) if respond_to?(name) end @source_hash = attributes[:source_hash] end |
Class Method Details
.from_hash(hash) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/pact_broker/db/clean/selector.rb', line 20 def self.from_hash(hash) standard_hash = hash.symbolize_keys.snakecase_keys new_hash = standard_hash.slice(*ATTRIBUTES) new_hash[:pacticipant_name] ||= standard_hash[:pacticipant] if standard_hash[:pacticipant] new_hash[:environment_name] ||= standard_hash[:environment] if standard_hash[:environment] new_hash[:source_hash] = hash new(new_hash.compact) end |
Instance Method Details
#currently_deployed? ⇒ Boolean
40 41 42 |
# File 'lib/pact_broker/db/clean/selector.rb', line 40 def currently_deployed? !!deployed end |
#currently_supported? ⇒ Boolean
44 45 46 |
# File 'lib/pact_broker/db/clean/selector.rb', line 44 def currently_supported? !!released end |
#latest? ⇒ Boolean
48 49 50 |
# File 'lib/pact_broker/db/clean/selector.rb', line 48 def latest? !!latest end |
#to_hash ⇒ Object Also known as: to_h
29 30 31 32 33 |
# File 'lib/pact_broker/db/clean/selector.rb', line 29 def to_hash ATTRIBUTES.each_with_object({}) do | key, hash | hash[key] = send(key) end.compact end |
#to_json(_opts = nil) ⇒ Object
36 37 38 |
# File 'lib/pact_broker/db/clean/selector.rb', line 36 def to_json(_opts = nil) (@source_hash || to_hash).to_json end |