summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/blink/client.rb15
-rw-r--r--lib/blink/types.rb42
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