expressir 2.4.13 → 2.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3cf38ff1a09f95805cc5a6dc8c074832e47eeb8ceb7e62c79f503d521d775ac
4
- data.tar.gz: a308605c1d7c97d33f766d08e8262e6e2039104ff7362e36a0fa5bd8e3839ccf
3
+ metadata.gz: ad3043a3dd1ac401e841249e3e081a7b3b6b3c3da99f6a9dbc136a127619ba49
4
+ data.tar.gz: '085e25b6e9b97d53fc5207aa651b37b080557626c6971b60029b98749ff4db82'
5
5
  SHA512:
6
- metadata.gz: 4c97b4d258e50604fba0bdc0365c3f8272d6944dc225755e6408c6b585324b917448134352a4ffb4da445ca21ef910858283931abef43625d0b4138c90ecf694
7
- data.tar.gz: d268fd6aef2e11bdafe5f81845931e91742dcd33ff48f3a2f6bb0076a6f9bad440045609a501b81fcc2130fef6dcd565d972ebc6634861d0341f9efa2649b5b5
6
+ metadata.gz: e92cca737def4e8432f30b98162262f83df7d81c719c7a1dd916173f65ff788c1145843e46131bfe7da5ef97e76c00a155215f7c4893befe7748601711438d93
7
+ data.tar.gz: 88d3f1008222838323a843a1b9a7117bf1b09465fa453de4bfd21868137b16439a680165e527555099ae67884cb8a77c8a2068e92b113f34408444c314482583
@@ -97,6 +97,11 @@ module Expressir
97
97
  check_where_rules(schema, t, t.where_rules)
98
98
  end
99
99
  schema.rules.each { |r| check_where_rules(schema, r, r.where_rules) }
100
+ schema.entities.each do |entity|
101
+ check_aggregate_bounds(schema, entity)
102
+ check_attrib_name_fun(schema, entity)
103
+ end
104
+ check_string_references(schema)
100
105
  check_unresolved_refs(schema)
101
106
  end
102
107
 
@@ -342,6 +347,82 @@ module Expressir
342
347
  :type if find_type(schema, id)
343
348
  end
344
349
 
350
+ # eeng check-agg-type: a two-bound aggregate whose lower bound
351
+ # exceeds its upper bound is invalid.
352
+ def check_aggregate_bounds(schema, entity)
353
+ entity.attributes.to_a.each do |attr|
354
+ type = attr.type
355
+ next unless type.respond_to?(:bound1) && type.respond_to?(:bound2)
356
+
357
+ lower = integer_bound(type.bound1)
358
+ upper = integer_bound(type.bound2)
359
+ next if lower.nil? || upper.nil?
360
+ next if lower <= upper
361
+
362
+ note!(:check_agg_type, :error, schema,
363
+ "ENTITY #{entity.id}: aggregate '#{attr.id}' bounds " \
364
+ "[#{lower}:#{upper}] are inverted", attr)
365
+ end
366
+ end
367
+
368
+ def integer_bound(bound)
369
+ return nil unless bound.is_a?(Model::Literals::Integer)
370
+
371
+ bound.value.to_i
372
+ rescue StandardError
373
+ nil
374
+ end
375
+
376
+ # eeng check-attrib-name-fun: an attribute sharing its name with
377
+ # a function of the same schema can never be referenced cleanly.
378
+ def check_attrib_name_fun(schema, entity)
379
+ funs = schema.functions.to_a.map { |f| f.id.safe_downcase }
380
+ entity.attributes.to_a.each do |attr|
381
+ next unless attr.id && funs.include?(attr.id.safe_downcase)
382
+
383
+ note!(:check_attrib_name_fun, :warning, schema,
384
+ "ENTITY #{entity.id}: attribute '#{attr.id}' shadows a " \
385
+ "function of the same name", attr)
386
+ end
387
+ end
388
+
389
+ # eeng check-string-no-entity: string literals of the shape
390
+ # 'SCHEMA.ITEM' whose SCHEMA is known in the repository but whose
391
+ # ITEM is not declared in it (the TYPEOF idiom).
392
+ def check_string_references(schema)
393
+ known = @by_name
394
+ each_string(schema) do |literal, value|
395
+ match = /\A(\w+)\.(\w+)\z/.match(value)
396
+ next unless match
397
+
398
+ schema_id = match[1].safe_downcase
399
+ item_id = match[2].safe_downcase
400
+ target = known[schema_id]&.find { |s| s.id.safe_downcase == schema_id }
401
+ next unless target
402
+ next if Expressir::Express::SelfSchemaReference.declared?(target, item_id)
403
+
404
+ note!(:check_string_no_entity, :warning, schema,
405
+ "string '#{value}' references '#{item_id}' which is not " \
406
+ "declared in schema '#{target.id}'", literal)
407
+ end
408
+ end
409
+
410
+ def each_string(node, &)
411
+ case node
412
+ when Model::Literals::String then yield node, node.value
413
+ when Model::ModelElement
414
+ node.class.attributes.each_key do |attr|
415
+ next if Model::ModelElement::SKIP_ATTRIBUTES.include?(attr) || attr == :parent
416
+
417
+ value = node.public_send(attr)
418
+ case value
419
+ when Array then value.each { |item| each_string(item, &) }
420
+ when Model::ModelElement then each_string(value, &)
421
+ end
422
+ end
423
+ end
424
+ end
425
+
345
426
  def check_where_rules(schema, owner, rules)
346
427
  Array(rules).each do |wr|
347
428
  next if wr.id.nil? || wr.id.match?(WHERE_LABEL)
@@ -3,6 +3,6 @@ module Expressir
3
3
  # autoload it (Ruby autoload only works for module/class constants, not
4
4
  # for string constants like `Expressir::VERSION`).
5
5
  module Version
6
- VERSION = "2.4.13".freeze
6
+ VERSION = "2.4.14".freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.13
4
+ version: 2.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.