Sha256: e51398bec37f050e9f6e4082acb87ed141fdd39a8a77cfb183f18969506c032c

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pact_broker-2.89.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.88.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.87.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.86.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.85.1 lib/pact_broker/db/clean/selector.rb
pact_broker-2.85.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.84.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.83.0 lib/pact_broker/db/clean/selector.rb