Class: ActiveFacts::Metamodel::Query
- Inherits:
-
Object
- Object
- ActiveFacts::Metamodel::Query
- Defined in:
- lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb
Instance Method Summary collapse
- #all_step ⇒ Object
- #describe ⇒ Object
- #show ⇒ Object
-
#validate ⇒ Object
Check all parts of this query for validity.
Instance Method Details
#all_step ⇒ Object
1021 1022 1023 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 1021 def all_step all_variable.map{|var| var.all_step.to_a}.flatten.uniq end |
#describe ⇒ Object
988 989 990 991 992 993 994 995 996 997 998 999 1000 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 988 def describe steps_shown = {} 'Query(' + all_variable.sort_by{|var| var.ordinal}.map do |variable| variable.describe + ': ' + variable.all_step.map do |step| next if steps_shown[step] steps_shown[step] = true step.describe end.compact.join(',') end.join('; ') + ')' end |
#show ⇒ Object
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 1002 def show steps_shown = {} trace :query, "Displaying full contents of Query #{concept.guid}" do all_variable.sort_by{|var| var.ordinal}.each do |variable| trace :query, "#{variable.describe}" do variable.all_step. each do |step| next if steps_shown[step] steps_shown[step] = true trace :query, "#{step.describe}" end variable.all_play.each do |play| trace :query, "role of #{play.describe} in '#{play.role.fact_type.default_reading}'" end end end end end |
#validate ⇒ Object
Check all parts of this query for validity
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 1026 def validate show return # Check the variables: steps = [] variables = all_variable.sort_by{|var| var.ordinal} variables.each_with_index do |variable, i| raise "Variable #{i} should have ordinal #{variable.ordinal}" unless variable.ordinal == i raise "Variable #{i} has missing object_type" unless variable.object_type variable.all_play do |play| raise "Variable for #{object_type.name} includes role played by #{play.object_type.name}" unless play.object_type == object_type end steps += variable.all_step end steps.uniq! # Check the steps: steps.each do |step| raise "Step has missing fact type" unless step.fact_type raise "Step has missing input node" unless step.input_play raise "Step has missing output node" unless step.output_play if (role = input_play).role.fact_type != fact_type or (role = output_play).role.fact_type != fact_type raise "Step has role #{role.describe} which doesn't belong to the fact type '#{fact_type.default_reading}' it traverses" end end # REVISIT: Do a connectivity check end |