Class: ActiveFacts::Metamodel::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/metamodel/metamodel.rb,
lib/activefacts/metamodel/extensions.rb

Instance Method Summary collapse

Instance Method Details

#describeObject



1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
# File 'lib/activefacts/metamodel/extensions.rb', line 1316

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

#showObject



1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
# File 'lib/activefacts/metamodel/extensions.rb', line 1330

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

#validateObject

Check all parts of this query for validity



1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
# File 'lib/activefacts/metamodel/extensions.rb', line 1350

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