-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clean): support keeping currently deployed and released versions…
…, and the latest version for each branch
- Loading branch information
Showing
6 changed files
with
221 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "pact_broker/hash_refinements" | ||
|
||
module PactBroker | ||
module DB | ||
class Clean | ||
class Selector | ||
using PactBroker::HashRefinements | ||
|
||
ATTRIBUTES = [:pacticipant_name, :latest, :tag, :branch, :environment_name, :max_age, :deployed, :released, :main_branch] | ||
|
||
attr_accessor *ATTRIBUTES | ||
|
||
def initialize(attributes = {}) | ||
attributes.each do | (name, value) | | ||
instance_variable_set("@#{name}", value) if respond_to?(name) | ||
end | ||
@source_hash = attributes[:source_hash] | ||
end | ||
|
||
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 | ||
|
||
def to_hash | ||
ATTRIBUTES.each_with_object({}) do | key, hash | | ||
hash[key] = send(key) | ||
end.compact | ||
end | ||
alias_method :to_h, :to_hash | ||
|
||
def to_json | ||
(@source_hash || to_hash).to_json | ||
end | ||
|
||
def currently_deployed? | ||
!!deployed | ||
end | ||
|
||
def currently_supported? | ||
!!released | ||
end | ||
|
||
def latest? | ||
!!latest | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters