diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/indirector/indirection.rb | 8 | ||||
-rw-r--r-- | lib/puppet/network/http/mongrel.rb | 4 | ||||
-rw-r--r-- | lib/puppet/network/http/mongrel/rest.rb | 14 | ||||
-rw-r--r-- | lib/puppet/network/http/webrick.rb | 6 | ||||
-rw-r--r-- | lib/puppet/network/http/webrick/rest.rb | 14 |
5 files changed, 39 insertions, 7 deletions
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 0d814c5ef..6930af494 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -13,6 +13,14 @@ class Puppet::Indirector::Indirection @@indirections.find { |i| i.name == name } end + # Find an indirected model by name. This is provided so that Terminus classes + # can specifically hook up with the indirections they are associated with. + def self.model(name) + match = @@indirections.find { |i| i.name == name } + return nil unless match + match.model + end + attr_accessor :name, :model # Create and return our cache terminus. diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb index 3efc465ad..bec94ac13 100644 --- a/lib/puppet/network/http/mongrel.rb +++ b/lib/puppet/network/http/mongrel.rb @@ -38,9 +38,7 @@ class Puppet::Network::HTTP::Mongrel def setup_handlers @protocols.each do |protocol| - @handlers.each do |handler| - class_for_protocol(protocol).new(:server => @server, :handler => handler) - end + class_for_protocol(protocol).new(:server => @server, :handlers => @handlers) end end diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb index 6e454c7d9..34f1d8f90 100644 --- a/lib/puppet/network/http/mongrel/rest.rb +++ b/lib/puppet/network/http/mongrel/rest.rb @@ -1,4 +1,18 @@ class Puppet::Network::HTTP::MongrelREST def initialize(args = {}) + raise ArgumentError unless args[:server] + raise ArgumentError if !args[:handlers] or args[:handlers].empty? + + @models = {} + args[:handlers].each do |handler| + @models[handler] = find_model_for_handler(handler) + end + end + + private + + def find_model_for_handler(handler) + Puppet::Indirector::Indirection.model(handler) || + raise(ArgumentError, "Cannot locate indirection [#{handler}].") end end diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb index 6df7804c6..21d191d06 100644 --- a/lib/puppet/network/http/webrick.rb +++ b/lib/puppet/network/http/webrick.rb @@ -41,10 +41,8 @@ class Puppet::Network::HTTP::WEBrick private def setup_handlers - @handlers.each do |handler| - @protocols.each do |protocol| - class_for_protocol(protocol).new(:server => @server, :handler => handler) - end + @protocols.each do |protocol| + class_for_protocol(protocol).new(:server => @server, :handlers => @handlers) end end diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb index 5e9ccfc45..f70f2030f 100644 --- a/lib/puppet/network/http/webrick/rest.rb +++ b/lib/puppet/network/http/webrick/rest.rb @@ -1,4 +1,18 @@ class Puppet::Network::HTTP::WEBrickREST def initialize(args = {}) + raise ArgumentError unless args[:server] + raise ArgumentError if !args[:handlers] or args[:handlers].empty? + + @models = {} + args[:handlers].each do |handler| + @models[handler] = find_model_for_handler(handler) + end + end + + private + + def find_model_for_handler(handler) + Puppet::Indirector::Indirection.model(handler) || + raise(ArgumentError, "Cannot locate indirection [#{handler}].") end end
\ No newline at end of file |