Add #length and #size methods to Registry
This commit is contained in:
parent
60a8472891
commit
bc4bbb9fc0
|
@ -34,7 +34,7 @@ module Vagrant
|
||||||
def has_key?(key)
|
def has_key?(key)
|
||||||
@items.has_key?(key)
|
@items.has_key?(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array populated with the keys of this object.
|
# Returns an array populated with the keys of this object.
|
||||||
#
|
#
|
||||||
# @return [Array]
|
# @return [Array]
|
||||||
|
@ -49,6 +49,14 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return the number of elements in this registry.
|
||||||
|
#
|
||||||
|
# @return [Fixnum]
|
||||||
|
def length
|
||||||
|
@items.keys.length
|
||||||
|
end
|
||||||
|
alias_method :size, :length
|
||||||
|
|
||||||
# Merge one registry with another and return a completely new
|
# Merge one registry with another and return a completely new
|
||||||
# registry. Note that the result cache is completely busted, so
|
# registry. Note that the result cache is completely busted, so
|
||||||
# any gets on the new registry will result in a cache miss.
|
# any gets on the new registry will result in a cache miss.
|
||||||
|
|
|
@ -90,6 +90,28 @@ describe Vagrant::Registry do
|
||||||
expect(result["bar"]).to eq("barvalue")
|
expect(result["bar"]).to eq("barvalue")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#length" do
|
||||||
|
it "should return 0 when the registry is empty" do
|
||||||
|
expect(instance.length).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return the number of items in the registry" do
|
||||||
|
instance.register("foo") { }
|
||||||
|
instance.register("bar") { }
|
||||||
|
|
||||||
|
expect(instance.length).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#size" do
|
||||||
|
it "should be an alias to #length" do
|
||||||
|
size = described_class.instance_method(:size)
|
||||||
|
length = described_class.instance_method(:length)
|
||||||
|
|
||||||
|
expect(size).to eq(length)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "merging" do
|
describe "merging" do
|
||||||
it "should merge in another registry" do
|
it "should merge in another registry" do
|
||||||
one = described_class.new
|
one = described_class.new
|
||||||
|
|
Loading…
Reference in New Issue