Sha256: 89513942e0bb7efd433f07e4f93b136aca02ac38eeda8cafdeb64be789f5406a

Contents?: true

Size: 1.09 KB

Versions: 48

Compression:

Stored size: 1.09 KB

Contents

require 'pact_broker/domain/group'

=begin
  Splits all relationships up into groups of non-connecting relationships.
=end

module PactBroker

  module Relationships

    class Groupify

      def self.call relationships
        recurse_groups([], relationships.dup).collect { |group| Domain::Group.new(group) }
      end

      def self.recurse_groups groups, relationship_pool
        if relationship_pool.empty?
          groups
        else
          first, *rest = relationship_pool
          group = [first]
          new_connections = true
          while new_connections
            new_connections = false
            group = rest.inject(group) do |connected, candidate|
              if connected.select { |relationship| relationship.connected?(candidate) }.any?
                new_connections = true
                connected + [candidate]
              else
                connected
              end
            end

            rest = rest - group
            group.uniq
          end

          recurse_groups(groups + [group], relationship_pool - group)
        end
      end
    end

  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
pact_broker-2.9.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.9.0.beta.5 lib/pact_broker/relationships/groupify.rb
pact_broker-2.8.0.beta.5 lib/pact_broker/relationships/groupify.rb
pact_broker-2.8.0.beta.4 lib/pact_broker/relationships/groupify.rb
pact_broker-2.7.0.beta.3 lib/pact_broker/relationships/groupify.rb
pact_broker-2.7.0.beta.2 lib/pact_broker/relationships/groupify.rb
pact_broker-2.7.0.beta.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.6.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.5.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.5.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.4.2 lib/pact_broker/relationships/groupify.rb
pact_broker-2.4.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.4.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.3.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.2.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.1.1 lib/pact_broker/relationships/groupify.rb
pact_broker-2.1.0 lib/pact_broker/relationships/groupify.rb
pact_broker-2.0.5 lib/pact_broker/relationships/groupify.rb
pact_broker-2.0.4 lib/pact_broker/relationships/groupify.rb
pact_broker-2.0.3 lib/pact_broker/relationships/groupify.rb