Sha256: 0dc43c54b656bb680de1ef2b819dec97ed2be2630f069cab0119ee244cbdfc26

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require "delegate"
require "forwardable"

module VagrantPlugins
  module CommandServe
    class Mappers
      module Internal
        class Graph
          # Wrapper around a vertex and used within the
          # graph to allow weighting edges for path
          # preference. All vertices within a graph are
          # WeightedVertex instances. Paths with the
          # lowest weights are preferred.
          class WeightedVertex < SimpleDelegator

            # Force the delegator to properly look like the
            # vertex its decorating
            extend Forwardable
            def_delegators :__getobj__, :is_a?, :kind_of?, :class

            attr_reader :weight

            def initialize(vertex, weight:)
              if !vertex.is_a?(Vertex)
                raise TypeError,
                  "Expected `Vertex' type, got `#{vertex.class}'"
              end
              self.weight = weight
              super(vertex)
            end

            def weight=(w)
              if !w.is_a?(Integer)
                raise TypeError,
                  "Expected `Integer' type for weight, got `#{w.class}'"
              end
              @weight = w
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/commands/serve/mappers/internal/graph/weighted_vertex.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/commands/serve/mappers/internal/graph/weighted_vertex.rb
vagrant-unbundled-2.3.3.0 plugins/commands/serve/mappers/internal/graph/weighted_vertex.rb
vagrant-unbundled-2.3.2.0 plugins/commands/serve/mappers/internal/graph/weighted_vertex.rb