diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2011-03-22 17:19:58 -0700 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2011-03-22 17:19:58 -0700 |
| commit | f7db67513cace1efaf054406dae040dab2c44efd (patch) | |
| tree | 1177637a9ae75527b14523d3803c610601e5d54b /lib/puppet/interface/interface_collection.rb | |
| parent | 01ce91816fe061267e9821c07fefb8aa14af4a14 (diff) | |
| parent | 847ac203f9c0b5fce299e87a63b0de5d3ef416f6 (diff) | |
| download | puppet-f7db67513cace1efaf054406dae040dab2c44efd.tar.gz puppet-f7db67513cace1efaf054406dae040dab2c44efd.tar.xz puppet-f7db67513cace1efaf054406dae040dab2c44efd.zip | |
Merge branch 'maint/master/always-use-interface-method'
Diffstat (limited to 'lib/puppet/interface/interface_collection.rb')
| -rw-r--r-- | lib/puppet/interface/interface_collection.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/puppet/interface/interface_collection.rb b/lib/puppet/interface/interface_collection.rb new file mode 100644 index 000000000..47ed702aa --- /dev/null +++ b/lib/puppet/interface/interface_collection.rb @@ -0,0 +1,50 @@ +require 'puppet/interface' + +module Puppet::Interface::InterfaceCollection + @interfaces = {} + + def self.interfaces + unless @loaded + @loaded = true + $LOAD_PATH.each do |dir| + next unless FileTest.directory?(dir) + Dir.chdir(dir) do + Dir.glob("puppet/interface/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file| + iname = file.sub(/\.rb/, '') + begin + require iname + rescue Exception => detail + puts detail.backtrace if Puppet[:trace] + raise "Could not load #{iname} from #{dir}/#{file}: #{detail}" + end + end + end + end + end + return @interfaces.keys + end + + def self.[](name) + @interfaces[underscorize(name)] if interface?(name) + end + + def self.interface?(name) + name = underscorize(name) + require "puppet/interface/#{name}" unless @interfaces.has_key? name + return @interfaces.has_key? name + rescue LoadError + return false + end + + def self.register(interface) + @interfaces[underscorize(interface.name)] = interface + end + + def self.underscorize(name) + unless name.to_s =~ /^[-_a-z]+$/i then + raise ArgumentError, "#{name.inspect} (#{name.class}) is not a valid interface name" + end + + name.to_s.downcase.split(/[-_]/).join('_').to_sym + end +end |
