lib/activefacts/api/vocabulary.rb in activefacts-api-0.9.2 vs lib/activefacts/api/vocabulary.rb in activefacts-api-0.9.3

- old
+ new

@@ -19,21 +19,23 @@ def object_type(name = nil) @object_type ||= {} return @object_type unless name if name.is_a? Class - raise "#{name} must be an object type in #{self.name}" unless name.vocabulary == self + unless name.respond_to?(:vocabulary) and name.vocabulary == self + raise CrossVocabularyRoleException.new(name, self) + end return name end camel = name.to_s.camelcase if (c = @object_type[camel]) __bind(camel) c else begin - const_get("#{self.name}::#{camel}") + const_get(camel) rescue NameError nil end end end @@ -62,23 +64,27 @@ @object_type ||= {} @object_type[klass.basename] = klass end def __delay(object_type_name, args, &block) #:nodoc: - @delayed ||= Hash.new { |h,k| h[k] = [] } - @delayed[object_type_name] << [args, block] + delayed[object_type_name] << [args, block] end # __bind raises an error if the named class doesn't exist yet. def __bind(object_type_name) #:nodoc: object_type = const_get(object_type_name) - if (@delayed && @delayed.include?(object_type_name)) - d = @delayed[object_type_name] + if (delayed.include?(object_type_name)) + d = delayed[object_type_name] d.each{|(a,b)| b.call(object_type, *a) } - @delayed.delete(object_type_name) + delayed.delete(object_type_name) end + end + + def delayed + @delayed ||= Hash.new { |h,k| h[k] = [] } + @delayed end end end end