From 9ab74271cfa6bccc73f63c6c157d25f64520ce47 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 13 Apr 2022 15:11:49 -0700 Subject: [PATCH] Add some comments and expand some method documentation --- .../commands/serve/mappers/internal/graph/search.rb | 12 ++++++++++++ .../commands/serve/mappers/internal/graph/vertex.rb | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/plugins/commands/serve/mappers/internal/graph/search.rb b/plugins/commands/serve/mappers/internal/graph/search.rb index d57b400a7..7dd565e78 100644 --- a/plugins/commands/serve/mappers/internal/graph/search.rb +++ b/plugins/commands/serve/mappers/internal/graph/search.rb @@ -281,6 +281,18 @@ module VagrantPlugins # applied. After the given block is executed, the value # vertices will have their original weights re-applied. # + # Since value vertices are identified by type, only + # one value of any type may exist in the graph. However, + # if the value is named, then multiple values of the same + # type may exist in the graph. For instance, with named + # values two strings could be provided, one named "local_path" + # and another named "remote_path". If a mapper function is + # only interested in the value of the "remote_path", it + # can include that name within its input definition. Then + # this method can be used to prefer the name string argument + # "remote_path" over the "local_path" named argument, or + # just a regular string value. + # # @param vertex [Vertex] source vertex # @param graph [Graph] graph to modify # @yieldparam [Graph] modified graph (passed instance, not a copy) diff --git a/plugins/commands/serve/mappers/internal/graph/vertex.rb b/plugins/commands/serve/mappers/internal/graph/vertex.rb index 553732cdd..601dde7a7 100644 --- a/plugins/commands/serve/mappers/internal/graph/vertex.rb +++ b/plugins/commands/serve/mappers/internal/graph/vertex.rb @@ -43,19 +43,29 @@ module VagrantPlugins value end + # Determine if provided vertex is equivalent + # + # @param [Vertex] + # @return [Boolean] def ==(v) v.hash_code == hash_code end alias_method :eql?, :== + # Generate a hash for the given vertex. This is used + # to uniquely identify a vertex within a Hash. + # + # @return [Integer] def hash hash_code.to_s.chars.map(&:ord).sum.hash end + # @return [String] def to_s "" end + # @return [String] def inspect "<#{self.class.name} value=#{value} hash=#{hash_code}>" end