summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface.rb
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-03-22 17:19:58 -0700
committerNick Lewis <nick@puppetlabs.com>2011-03-22 17:19:58 -0700
commitf7db67513cace1efaf054406dae040dab2c44efd (patch)
tree1177637a9ae75527b14523d3803c610601e5d54b /lib/puppet/interface.rb
parent01ce91816fe061267e9821c07fefb8aa14af4a14 (diff)
parent847ac203f9c0b5fce299e87a63b0de5d3ef416f6 (diff)
downloadpuppet-f7db67513cace1efaf054406dae040dab2c44efd.tar.gz
puppet-f7db67513cace1efaf054406dae040dab2c44efd.tar.xz
puppet-f7db67513cace1efaf054406dae040dab2c44efd.zip
Merge branch 'maint/master/always-use-interface-method'
Diffstat (limited to 'lib/puppet/interface.rb')
-rw-r--r--lib/puppet/interface.rb74
1 files changed, 19 insertions, 55 deletions
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 0ec0f803f..f82d6235c 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -3,6 +3,7 @@ require 'puppet/util/autoload'
class Puppet::Interface
require 'puppet/interface/action_manager'
+ require 'puppet/interface/interface_collection'
include Puppet::Interface::ActionManager
extend Puppet::Interface::ActionManager
@@ -19,50 +20,27 @@ class Puppet::Interface
end
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
+ Puppet::Interface::InterfaceCollection.interfaces
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.interface(name, &blk)
- interface = interface?(name) ? @interfaces[underscorize(name)] : new(name)
- interface.instance_eval(&blk) if block_given?
- return interface
+ Puppet::Interface::InterfaceCollection.interface?(name)
end
- def self.register_interface(name, instance)
- @interfaces[underscorize(name)] = instance
+ def self.register(instance)
+ Puppet::Interface::InterfaceCollection.register(instance)
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"
+ def self.interface(name, &blk)
+ if interface?(name)
+ interface = Puppet::Interface::InterfaceCollection[name]
+ interface.instance_eval(&blk) if blk
+ else
+ interface = new(name, &blk)
+ Puppet::Interface::InterfaceCollection.register(interface)
+ interface.load_actions
end
-
- name.to_s.downcase.split(/[-_]/).join('_').to_sym
+ return interface
end
attr_accessor :default_format
@@ -71,30 +49,16 @@ class Puppet::Interface
self.default_format = format.to_sym
end
- # Return the interface name.
- def name
- @name || self.to_s.sub(/.+::/, '').downcase
- end
-
- attr_accessor :type, :verb, :name, :arguments, :options
+ attr_accessor :type, :verb, :arguments, :options
+ attr_reader :name
def initialize(name, options = {}, &block)
- @name = self.class.underscorize(name)
+ @name = Puppet::Interface::InterfaceCollection.underscorize(name)
@default_format = :pson
options.each { |opt, val| send(opt.to_s + "=", val) }
- # We have to register before loading actions,
- # since the actions require the registration
- # Use the full class name, so this works with
- # subclasses.
- Puppet::Interface.register_interface(name, self)
-
- load_actions
-
- if block_given?
- instance_eval(&block)
- end
+ instance_eval(&block) if block
end
# Try to find actions defined in other files.
@@ -102,7 +66,7 @@ class Puppet::Interface
path = "puppet/interface/#{name}"
loaded = []
- self.class.autoloader.search_directories.each do |dir|
+ Puppet::Interface.autoloader.search_directories.each do |dir|
fdir = ::File.join(dir, path)
next unless FileTest.directory?(fdir)