summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-17 16:29:43 -0700
committerLuke Kanies <luke@madstop.com>2007-09-17 16:29:43 -0700
commit76b34f57a4717fba6665656c4955b9f0abacdf74 (patch)
treeeee5bb52ecc7c8a66eaa3dbd0f958db201b11215
parent3ccf483f77b026dde8a53bd8e9dff6a5fd0f6722 (diff)
parent19e049322879f5195b6fb653ae0c63e776e94835 (diff)
Merge branch 'indirection' of http://git.rickbradley.com/puppet into indirection
-rw-r--r--lib/puppet/indirector.rb33
-rw-r--r--lib/puppet/indirector/indirection.rb2
-rwxr-xr-xspec/bin/spec1
-rw-r--r--spec/lib/spec/dsl/behaviour.rb2
-rw-r--r--spec/spec_helper.rb5
-rwxr-xr-xspec/unit/indirector/indirector.rb83
6 files changed, 113 insertions, 13 deletions
diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb
index 704039abc..13cf3991f 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -42,7 +42,7 @@ module Puppet::Indirector
# Set up autoloading of the appropriate termini.
instance_load name, "puppet/indirector/%s" % name
end
-
+
# Define a new indirection terminus. This method is used by the individual
# termini in their separate files. Again, the autoloader takes care of
# actually loading these files.
@@ -77,14 +77,36 @@ module Puppet::Indirector
if defined?(@indirection)
raise ArgumentError, "Already performing an indirection of %s; cannot redirect %s" % [@indirection.name, indirection]
end
+
+ # JRB: this associates an indirection class with this class (e.g., Node.@indirection = Indirection.new(:node))
@indirection = Indirection.new(indirection, options)
# Set up autoloading of the appropriate termini.
Puppet::Indirector.register_indirection indirection
- return @indirection
+ extend ClassMethods
+ include InstanceMethods
end
+ module InstanceMethods
+ # these become instance methods
+ def save
+ end
+ end
+
+ module ClassMethods
+ def find
+ end
+
+ def destroy
+ end
+
+ def search
+ end
+ end
+
+ # JRB:FIXME: these methods to be deprecated:
+
# Define methods for each of the HTTP methods. These just point to the
# termini, with consistent error-handling. Each method is called with
# the first argument being the indirection type and the rest of the
@@ -103,14 +125,13 @@ module Puppet::Indirector
private
- # Redirect a given HTTP method.
+
+ # Redirect one of our methods to the corresponding method on the Terminus
def redirect(method_name, *args)
begin
@indirection.terminus.send(method_name, *args)
rescue NoMethodError => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise ArgumentError, "The %s terminus of the %s indirection failed to respond to %s: %s" %
[@indirection.terminus.name, @indirection.name, method_name, detail]
end
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 7a4c4bd55..67b8a9d48 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -6,7 +6,7 @@ class Puppet::Indirector::Indirection
def self.clear_cache
@@indirections.each { |ind| ind.clear_cache }
end
-
+
attr_accessor :name, :termini
attr_reader :to
diff --git a/spec/bin/spec b/spec/bin/spec
index a7e6ce0cb..aaf320f34 100755
--- a/spec/bin/spec
+++ b/spec/bin/spec
@@ -1,3 +1,4 @@
+#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
require 'spec'
::Spec::Runner::CommandLine.run(ARGV, STDERR, STDOUT, true, true)
diff --git a/spec/lib/spec/dsl/behaviour.rb b/spec/lib/spec/dsl/behaviour.rb
index 93a357f19..159a0ba7e 100644
--- a/spec/lib/spec/dsl/behaviour.rb
+++ b/spec/lib/spec/dsl/behaviour.rb
@@ -1,4 +1,4 @@
-require 'puppettest/runnable_test'
+require(File.expand_path(File.dirname(__FILE__) + '../../../../../test/lib/puppettest/runnable_test.rb'))
module Spec
module DSL
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 477842495..3017f272a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,5 +1,6 @@
-dir = File.dirname(__FILE__)
-$:.unshift("#{dir}/lib").unshift("#{dir}/../lib")
+dir = File.expand_path(File.dirname(__FILE__))
+$:.unshift("#{dir}/lib")
+$:.unshift("#{dir}/../lib")
# Add the old test dir, so that we can still find mocha and spec
$:.unshift("#{dir}/../test/lib")
diff --git a/spec/unit/indirector/indirector.rb b/spec/unit/indirector/indirector.rb
index 312c60951..489ac57c4 100755
--- a/spec/unit/indirector/indirector.rb
+++ b/spec/unit/indirector/indirector.rb
@@ -5,9 +5,86 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/defaults'
require 'puppet/indirector'
+class TestThingie
+ extend Puppet::Indirector
+ indirects :thingie
+end
+
+class TestNormalThingie
+end
+
+describe Puppet::Indirector, " when included into a class" do
+ before do
+ @thingie = Class.new
+ @thingie.send(:extend, Puppet::Indirector)
+ end
+
+ it "should provide the indirects method to the class" do
+ @thingie.should respond_to(:indirects)
+ end
+
+ it "should require a name to register when indirecting" do
+ Proc.new {@thingie.send(:indirects) }.should raise_error(ArgumentError)
+ end
+
+ it "should require each indirection to be registered under a unique name" do
+ @thingie.send(:indirects, :name)
+ Proc.new {@thingie.send(:indirects, :name)}.should raise_error(ArgumentError)
+ end
+
+ it "should not allow a class to register multiple indirections" do
+ @thingie.send(:indirects, :first)
+ Proc.new {@thingie.send(:indirects, :second)}.should raise_error(ArgumentError)
+ end
+
+ it "should provide a way to access the list of registered classes"
+
+ it "should provide a way to find a class, given the registered name"
+
+ it "should make a find method available on the registered class" do
+ @thingie.send(:indirects, :first)
+ @thingie.should respond_to(:find)
+ end
+
+ it "should make a destroy method available on the registered class" do
+ @thingie.send(:indirects, :first)
+ @thingie.should respond_to(:destroy)
+ end
+
+ it "should make a search method available on the registered class" do
+ @thingie.send(:indirects, :first)
+ @thingie.should respond_to(:search)
+ end
+
+ it "should make a save method available on instances of the registered class" do
+ @thing = TestThingie.new
+ @thing.should respond_to(:save)
+ end
+
+
+
+ # when dealing with Terminus methods
+ it "should look up the indirection configuration for the registered class when a new instance of that class is created"
+
+ it "should use the Terminus described in the class configuration"
+
+ it "should use the Terminus find method when calling find on the registered class"
+ it "should use the Terminus save method when calling save on the registered class"
+ it "should use the Terminus destroy method when calling destroy on the registered class"
+ it "should use the Terminus search method when calling search on the registered class"
+
+ it "should allow a registered class to specify its own means of ..."
+end
+
+
+
+
+
+
+
describe Puppet::Indirector, " when managing indirections" do
before do
- @indirector = Object.new
+ @indirector = Class.new
@indirector.send(:extend, Puppet::Indirector)
end
@@ -24,7 +101,7 @@ describe Puppet::Indirector, " when managing indirections" do
it "should allow multiple classes to use the same indirection" do
@indirector.indirects :test
- other = Object.new
+ other = Class.new
other.send(:extend, Puppet::Indirector)
proc { other.indirects :test }.should_not raise_error
end
@@ -41,7 +118,7 @@ end
describe Puppet::Indirector, " when performing indirections" do
before do
- @indirector = Object.new
+ @indirector = Class.new
@indirector.send(:extend, Puppet::Indirector)
@indirector.indirects :test, :to => :node_source