lib/activefacts/generate/ruby.rb in activefacts-0.7.3 vs lib/activefacts/generate/ruby.rb in activefacts-0.8.5

- old
+ new

@@ -50,12 +50,12 @@ # We map DateAndTime to DateTime; if such a ValueType exists, don't dump this one return if is_special_supertype && o.name == 'DateAndTime' && o.constellation.ValueType[[[o.vocabulary.name], 'DateTime']] return if !o.supertype && !is_special_supertype if o.supertype && o.name == o.supertype.name - # In ActiveFacts, parameterising a ValueType will create a new datatype - # throw Can't handle parameterized value type of same name as its datatype" if ... + # In ActiveFacts, parameterising a ValueType will create a new ValueType + # throw Can't handle parameterized value type of same name as its ValueType" if ... end length = (l = o.length) && l > 0 ? ":length => #{l}" : nil scale = (s = o.scale) && s > 0 ? ":scale => #{s}" : nil params = [length,scale].compact * ", " @@ -74,11 +74,11 @@ puts " class #{name} < #{ruby_type_name}\n" + " value_type #{params}\n" if @sql and o.is_table puts " table" end - puts " \# REVISIT: #{o.name} has restricted values\n" if o.value_restriction + puts " restrict #{o.value_restriction.all_allowed_range_sorted.map{|ar| ar.to_s}*", "}\n" if o.value_restriction puts " \# REVISIT: #{o.name} is in units of #{o.unit.name}\n" if o.unit roles_dump(o) puts " end\n\n" end @@ -145,29 +145,31 @@ def unary_dump(role, role_name) puts " maybe :"+role_name end - def binary_dump(role, role_name, role_player, one_to_one = nil, readings = nil, other_role_name = nil, other_method_name = nil) + def binary_dump(role, role_name, role_player, mandatory = nil, one_to_one = nil, readings = nil, other_role_name = nil, other_method_name = nil) # Find whether we need the name of the other role player, and whether it's defined yet: if role_name.camelcase(true) == role_player.name.sub(/^[a-z]/) {|i| i.upcase} # Don't use Class name if implied by rolename role_reference = nil else - role_reference = concept_reference(role_player) + role_reference = ":class => "+concept_reference(role_player) end - other_role_name = ":"+other_role_name if other_role_name + other_role_name = ":counterpart => :"+other_role_name if other_role_name line = " #{one_to_one ? "one_to_one" : "has_one" } " + [ ":"+role_name, role_reference, + mandatory ? ":mandatory => true" : nil, readings, - other_role_name + other_role_name, + (vr = role.role_value_restriction) ? ":restrict => #{vr}" : nil ].compact*", "+" " line += " "*(48-line.length) if line.length < 48 line += "\# See #{role_player.name}.#{other_method_name}" if other_method_name puts line - puts " \# REVISIT: #{other_role_name} has restricted values\n" if role.role_value_restriction + #puts " \# REVISIT: #{other_role_name} has values restricted to #{role.role_value_restriction}\n" if role.role_value_restriction end def concept_reference concept if !@concept_types_dumped[concept] '"'+concept.name+'"'