From 2b03838fba4fb5be296c81af869f0572bfccdcc2 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 23 Oct 2014 11:23:55 -0400 Subject: [PATCH] Make Registry enumerable Registry already responds to #each, so including the Enumerable module gives us nice methods like #select and #collect fo' free! --- lib/vagrant/registry.rb | 2 ++ test/unit/vagrant/registry_test.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/vagrant/registry.rb b/lib/vagrant/registry.rb index f26e17d4f..4e401777b 100644 --- a/lib/vagrant/registry.rb +++ b/lib/vagrant/registry.rb @@ -4,6 +4,8 @@ module Vagrant # This allows certain components (such as guest systems, configuration # pieces, etc.) to be registered and queried, lazily. class Registry + include Enumerable + def initialize @items = {} @results_cache = {} diff --git a/test/unit/vagrant/registry_test.rb b/test/unit/vagrant/registry_test.rb index 3a33e9634..94364404c 100644 --- a/test/unit/vagrant/registry_test.rb +++ b/test/unit/vagrant/registry_test.rb @@ -3,6 +3,10 @@ require File.expand_path("../../base", __FILE__) describe Vagrant::Registry do let(:instance) { described_class.new } + it "should include enumerable" do + expect(instance).to be_a(Enumerable) + end + it "should return nil for nonexistent items" do expect(instance.get("foo")).to be_nil end