Sha256: 391469ff8da1c238d2c1e46691783b1a26ca5c3cea69324a35dd0e2683939364

Contents?: true

Size: 1.44 KB

Versions: 34

Compression:

Stored size: 1.44 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(_opts = nil)
          (@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

34 entries across 34 versions & 1 rubygems

Version Path
pact_broker-2.113.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.112.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.111.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.109.1 lib/pact_broker/db/clean/selector.rb
pact_broker-2.109.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.108.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.107.1 lib/pact_broker/db/clean/selector.rb
pact_broker-2.107.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/db/clean/selector.rb
pact_broker-2.106.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.105.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.104.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.103.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.102.2 lib/pact_broker/db/clean/selector.rb
pact_broker-2.102.1 lib/pact_broker/db/clean/selector.rb
pact_broker-2.102.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.101.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.100.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.99.0 lib/pact_broker/db/clean/selector.rb
pact_broker-2.98.0 lib/pact_broker/db/clean/selector.rb