diff options
author | Luke Kanies <luke@madstop.com> | 2005-04-14 22:01:15 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-04-14 22:01:15 +0000 |
commit | 13f16b6690224758706e1c68d1da577a13df8be5 (patch) | |
tree | 428a1bc778b74363a130a5627ad2d5fae2e1e16d | |
parent | 6140bee579c92cb89fc91ff8514a7796202a28fb (diff) | |
download | puppet-13f16b6690224758706e1c68d1da577a13df8be5.tar.gz puppet-13f16b6690224758706e1c68d1da577a13df8be5.tar.xz puppet-13f16b6690224758706e1c68d1da577a13df8be5.zip |
the client is now successfully creating objects from the hashes passed by the server
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@162 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/blink/client.rb | 15 | ||||
-rw-r--r-- | lib/blink/types.rb | 42 |
2 files changed, 52 insertions, 5 deletions
diff --git a/lib/blink/client.rb b/lib/blink/client.rb index 79c49f367..670aae4ad 100644 --- a/lib/blink/client.rb +++ b/lib/blink/client.rb @@ -6,6 +6,7 @@ require 'blink' require 'blink/function' +require 'blink/types' module Blink class ClientError < RuntimeError; end @@ -23,8 +24,22 @@ module Blink end def objects=(list) + Blink::Types.buildtypehash # refresh the list of available types + + objects = [] list.each { |object| # 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) + end + obj = type.new(object) + else + raise "Could not find object type %s" % object.type + end } end end diff --git a/lib/blink/types.rb b/lib/blink/types.rb index be6c8cf23..3f590338d 100644 --- a/lib/blink/types.rb +++ b/lib/blink/types.rb @@ -25,7 +25,14 @@ module Blink @@typeary = [] @@typehash = Hash.new { |hash,key| - raise "Object type %s not found" % key + if key.is_a?(String) + key = key.intern + end + if hash.include?(key) + hash[key] + else + raise "Object type %s not found" % key + end } #--------------------------------------------------------------- @@ -89,6 +96,22 @@ module Blink #----------------------------------- #----------------------------------- + def Types.newtype(type) + @@typeary.push(type) + if @@typehash.has_key?(type.name) + Blink.notice("Redefining object type %s" % type.name) + end + @@typehash[type.name] = type + end + #----------------------------------- + + #----------------------------------- + def Types.type(type) + @@typehash[type] + end + #----------------------------------- + + #----------------------------------- # accessor for the list of acceptable params def Types.classparams return @params @@ -101,10 +124,17 @@ module Blink def Types.classparambyname unless defined? @paramsbyname @paramsbyname = Hash.new { |hash,key| - fail TypeError.new( - "Parameter %s is invalid for class %s" % - [key.to_s,self] - ) + if key.is_a?(String) + key = key.intern + end + if hash.include?(key) + hash[key] + else + fail TypeError.new( + "Parameter %s is invalid for class %s" % + [key.to_s,self] + ) + end } @params.each { |param| if param.is_a? Symbol @@ -356,6 +386,8 @@ module Blink self[self.class.namevar] = hash[self.class.namevar] hash.delete(self.class.namevar) else + p hash + p self.class.namevar raise TypeError.new("A name must be provided at initialization time") end |