class ActiveFacts::Metamodel::Query

Public Instance Methods

describe() click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 1321
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() click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 1335
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() click to toggle source

Check all parts of this query for validity

# File lib/activefacts/metamodel/extensions.rb, line 1355
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