lib/mida/vocabulary.rb in mida-0.3.2 vs lib/mida/vocabulary.rb in mida-0.3.3
- old
+ new
@@ -36,27 +36,33 @@
def self.inherited(subclass)
register(subclass)
end
# Return the properties specification
+ # This won't work properly until all the included_vocabularies
+ # have finished being defined in case of circular dependancies
def self.properties
- @properties ||= {}
+ return @properties if @properties
+ @properties = @this_properties || {}
+ included_vocabularies.each do |vocabulary|
+ @properties.merge!(vocabulary.properties)
+ end
+ @properties
end
# Return the included vocabularies
def self.included_vocabularies
@included_vocabularies ||= Set.new
end
- # Include the properties from the specified <tt>vocabularies</tt>.
+ # Specify which +vocabularies+ will have their properties included.
# This is the correct way to inherit properties from another vocabulary,
# rather than subclassing.
def self.include_vocabulary(*vocabularies)
vocabularies.each do |vocabulary|
included_vocabularies.merge(vocabulary.included_vocabularies)
included_vocabularies << vocabulary
- properties.merge!(vocabulary.properties)
end
end
# As per the standard <tt>kind_of?</tt>, but also checks to see if vocabulary has
# been included by self
@@ -71,11 +77,10 @@
def self.itemtype(regexp=nil)
return @itemtype unless regexp
@itemtype = regexp
end
-
# Defines the properties as only containing one value
# If want to say any property name, then use +:any+ as a name
# Within a block you can use the methods of the class +PropertyDesc+
def self.has_one(*property_names, &block)
has(:one, *property_names, &block)
@@ -87,11 +92,11 @@
def self.has_many(*property_names, &block)
has(:many, *property_names, &block)
end
def self.has(num, *property_names, &block)
- @properties ||= {}
- property_names.each_with_object(@properties) do |name, properties|
+ @this_properties ||= {}
+ property_names.each_with_object(@this_properties) do |name, properties|
property_desc = PropertyDesc.new(num, &block)
properties[name] = property_desc.to_h
end
end