summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorPieter van de Bruggen <pieter@puppetlabs.com>2011-03-24 09:25:33 -0700
committerPieter van de Bruggen <pieter@puppetlabs.com>2011-03-25 08:59:08 -0700
commit78371a739bcf1b1d76496e9038fa4b076a27032f (patch)
treea68cf44c603f4e90f520b3805547a0858a3b634f /lib/puppet
parent53b0656048c3227048bdc317c5e917ad0c39e850 (diff)
downloadpuppet-78371a739bcf1b1d76496e9038fa4b076a27032f.tar.gz
puppet-78371a739bcf1b1d76496e9038fa4b076a27032f.tar.xz
puppet-78371a739bcf1b1d76496e9038fa4b076a27032f.zip
(#6770) Refactor Puppet::Interface#initialize.
P::I#initialize now takes a name and a version (and an optional block). The options hash has been removed, though it may be reintroduced if a legitimate use case can be made for it (so far, it's only been used for the version number). Reviewed-By: Jacob Helwig
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/interface.rb23
-rw-r--r--lib/puppet/interface/interface_collection.rb2
2 files changed, 11 insertions, 14 deletions
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 64f1bfe49..27cbb7522 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -30,15 +30,17 @@ class Puppet::Interface
Puppet::Interface::InterfaceCollection.register(instance)
end
- def define(name, version, &blk)
+ def define(name, version, &block)
if interface?(name, version)
interface = Puppet::Interface::InterfaceCollection[name, version]
- interface.instance_eval(&blk) if blk
else
- interface = self.new(name, :version => version, &blk)
+ interface = self.new(name, version)
Puppet::Interface::InterfaceCollection.register(interface)
interface.load_actions
end
+
+ interface.instance_eval(&block) if block_given?
+
return interface
end
@@ -54,22 +56,17 @@ class Puppet::Interface
attr_accessor :type, :verb, :version, :arguments, :options
attr_reader :name
- def initialize(name, options = {}, &block)
- unless options[:version]
- raise ArgumentError, "Interface #{name} declared without version!"
- end
-
+ def initialize(name, version, &block)
@name = Puppet::Interface::InterfaceCollection.underscorize(name)
-
+ @version = version
@default_format = :pson
- options.each { |opt, val| send(opt.to_s + "=", val) }
- instance_eval(&block) if block
+ instance_eval(&block) if block_given?
end
# Try to find actions defined in other files.
def load_actions
- path = "puppet/interface/#{name}"
+ path = "puppet/interface/v#{version}/#{name}"
loaded = []
Puppet::Interface.autoloader.search_directories.each do |dir|
@@ -92,6 +89,6 @@ class Puppet::Interface
end
def to_s
- "Puppet::Interface(#{name}, :version => #{version.inspect})"
+ "Puppet::Interface[#{name.inspect}, #{version.inspect}]"
end
end
diff --git a/lib/puppet/interface/interface_collection.rb b/lib/puppet/interface/interface_collection.rb
index d626c4f72..51b7534a0 100644
--- a/lib/puppet/interface/interface_collection.rb
+++ b/lib/puppet/interface/interface_collection.rb
@@ -9,7 +9,7 @@ module Puppet::Interface::InterfaceCollection
$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|
+ Dir.glob("puppet/interface/v*/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file|
iname = file.sub(/\.rb/, '')
begin
require iname