diff options
| author | Luke Kanies <luke@madstop.com> | 2005-04-15 20:09:07 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-04-15 20:09:07 +0000 |
| commit | 3904d2efd505fec08de3c4e8e7ab6d14586aed7e (patch) | |
| tree | 44f211e5d548037f5f1ff98289273edd09ac898f | |
| parent | 13f16b6690224758706e1c68d1da577a13df8be5 (diff) | |
| download | puppet-3904d2efd505fec08de3c4e8e7ab6d14586aed7e.tar.gz puppet-3904d2efd505fec08de3c4e8e7ab6d14586aed7e.tar.xz puppet-3904d2efd505fec08de3c4e8e7ab6d14586aed7e.zip | |
fixing most of the function call stuff
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@167 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/blink/client.rb | 10 | ||||
| -rw-r--r-- | lib/blink/fact.rb | 24 | ||||
| -rw-r--r-- | lib/blink/function.rb | 37 | ||||
| -rw-r--r-- | test/blinktest.rb | 3 | ||||
| -rw-r--r-- | test/client/tc_client.rb | 3 | ||||
| -rw-r--r-- | test/other/tc_fact.rb | 28 |
6 files changed, 91 insertions, 14 deletions
diff --git a/lib/blink/client.rb b/lib/blink/client.rb index 670aae4ad..cef92cfa8 100644 --- a/lib/blink/client.rb +++ b/lib/blink/client.rb @@ -15,11 +15,14 @@ module Blink attr_accessor :objects class Local - def callfunc(name,*args) + def callfunc(name,args) if function = Blink::Function[name] - return function.call(*args) + #Blink.debug("calling function %s" % function) + value = function.call(args) + #Blink.debug("from %s got %s" % [name,value]) + return value else - return nil + raise "Function '%s' not found" % name end end @@ -31,7 +34,6 @@ module Blink # create a Blink object from the list... if type = Blink::Types.type(object.type) namevar = type.namevar - Blink.notice("%s namevar is %s" % [type.name,namevar]) if namevar != :name object[namevar] = object[:name] object.delete(:name) diff --git a/lib/blink/fact.rb b/lib/blink/fact.rb index 4da297828..de7d7aae0 100644 --- a/lib/blink/fact.rb +++ b/lib/blink/fact.rb @@ -9,12 +9,18 @@ # currently a very thin veneer on 'facter' require 'facter' +require 'blink' require 'blink/types' module Blink class Fact < Blink::Interface def Fact.[](name) - Facter[name].value + fact = Facter[name] + if fact.value.nil? + raise "Could not retrieve fact %s" % name + end + Blink.debug("fact: got %s from %s for %s" % [fact.value,fact,name]) + return fact.value end # just pass the block to 'add' @@ -35,16 +41,22 @@ module Blink Blink::Types.newtype(self) + # we're adding a new resolution mechanism here; this is just how + # types work + # we don't have any real interest in the returned object def initialize(hash) name = hash[:name] hash.delete(:name) Fact.add(name) { |fact| - p fact + method = nil hash.each { |key,value| - method = key + "=" - #if key.is_a?(String) - # key = key.intern - #end + if key.is_a?(String) + method = key + "=" + elsif key.is_a?(Symbol) + method = key.id2name + "=" + else + raise "Key must be either string or symbol" + end fact.send(method,value) } } diff --git a/lib/blink/function.rb b/lib/blink/function.rb index 9e67b0071..4f10fb2c6 100644 --- a/lib/blink/function.rb +++ b/lib/blink/function.rb @@ -16,8 +16,8 @@ module Blink #--------------------------------------------------------------- #--------------------------------------------------------------- - def call(*args) - @code.call(*args) + def call(args) + @code.call(args) end #--------------------------------------------------------------- @@ -36,6 +36,37 @@ module Blink Function.new("retrieve", proc { |fact| require 'blink/fact' - return Fact[fact] + value = Fact[fact] + Blink.debug("retrieved %s as %s" % [fact,value]) + value + }) + + Function.new("addfact", proc { |args| + require 'blink/fact' + #Blink.debug("running addfact") + + hash = nil + if args.is_a?(Array) + hash = Hash[*args] + end + name = nil + if hash.has_key?("name") + name = hash["name"] + hash.delete("name") + elsif hash.has_key?(:name) + name = hash[:name] + hash.delete(:name) + else + raise "Functions must have names" + end + #Blink.debug("adding fact %s" % name) + newfact = Fact.add(name) { |fact| + hash.each { |key,value| + method = key + "=" + fact.send(method,value) + } + } + + #Blink.debug("got fact %s" % newfact) }) end diff --git a/test/blinktest.rb b/test/blinktest.rb index 1804f48e1..f44167486 100644 --- a/test/blinktest.rb +++ b/test/blinktest.rb @@ -46,7 +46,8 @@ unless defined? BlinkTestSuite File.join(textdir,file) }.find_all { |file| FileTest.file?(file) - }.each { |file| + }.sort.each { |file| + puts "Processing %s" % file yield file } end diff --git a/test/client/tc_client.rb b/test/client/tc_client.rb index e7cbd6ef9..21d308e04 100644 --- a/test/client/tc_client.rb +++ b/test/client/tc_client.rb @@ -27,4 +27,7 @@ class TestClient < Test::Unit::TestCase ) } end + + def test_files + end end diff --git a/test/other/tc_fact.rb b/test/other/tc_fact.rb new file mode 100644 index 000000000..c1aaafa72 --- /dev/null +++ b/test/other/tc_fact.rb @@ -0,0 +1,28 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $blinkbase = "../.." +end + +require 'blink/fact' +require 'test/unit' + +# $Id$ + +class TestFacts < Test::Unit::TestCase + def test_newfact + Blink[:debug] = true if __FILE__ == $0 + fact = nil + assert_nothing_raised() { + fact = Blink::Fact.new( + :name => "funtest", + :code => "echo funtest", + :interpreter => "/bin/sh" + ) + } + assert_equal( + "funtest", + Blink::Fact["funtest"] + ) + end +end |
