lib/activefacts/persistence/reference.rb in activefacts-1.3.0 vs lib/activefacts/persistence/reference.rb in activefacts-1.5.0

- old
+ new

@@ -90,11 +90,11 @@ @to && !@to_role && @from_role end # If this Reference is from an objectified FactType, there is no *from_role* def is_from_objectified_fact - @to && @to_role && !@from_role + @to && !@from_role && @to_role end # Is this reference an injected role as a result a ValueType being a table? def is_self_value !@to && !@to_role @@ -207,9 +207,29 @@ end # The reading for the fact type underlying this Reference def reading is_self_value ? "#{from.name} has value" : @fact_type.reading_preferably_starting_with_role(@from_role).expand + end + + def verbalised_path reverse = false + return "#{from.name} Value" if is_self_value + objectified = fact_type.entity_type + f = # Switch to the Link Fact Type if we're traversing an objectification + (to_role && to_role.link_fact_type) || + (from_role && from_role.link_fact_type) || + fact_type + + start_role = + if objectified + target = reverse ? to : from + [to_role, from_role, f.all_role[0]].compact.detect{|role| role.object_type == target} + else + reverse ? to_role : from_role + end + reading = f.reading_preferably_starting_with_role(start_role) + (is_mandatory || is_unary ? '' : 'maybe ') + + reading.expand end def inspect #:nodoc: to_s end