expressir 2.1.22 → 2.1.23
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 +4 -4
- data/.rubocop.yml +9 -9
- data/.rubocop_todo.yml +62 -64
- data/Gemfile +2 -2
- data/README.adoc +202 -5
- data/bin/rspec +2 -1
- data/docs/liquid_drops.adoc +1 -1
- data/expressir.gemspec +0 -2
- data/lib/expressir/benchmark.rb +6 -3
- data/lib/expressir/cli.rb +24 -12
- data/lib/expressir/commands/benchmark.rb +7 -16
- data/lib/expressir/commands/benchmark_cache.rb +9 -17
- data/lib/expressir/commands/coverage.rb +43 -42
- data/lib/expressir/coverage.rb +41 -15
- data/lib/expressir/express/cache.rb +2 -1
- data/lib/expressir/express/formatter.rb +54 -12
- data/lib/expressir/express/hyperlink_formatter.rb +2 -1
- data/lib/expressir/express/parser.rb +329 -112
- data/lib/expressir/express/schema_head_formatter.rb +2 -1
- data/lib/expressir/express/visitor.rb +114 -51
- data/lib/expressir/model/declarations/entity.rb +2 -1
- data/lib/expressir/model/declarations/informal_proposition_rule.rb +24 -0
- data/lib/expressir/model/declarations/rule.rb +2 -1
- data/lib/expressir/model/declarations/schema.rb +4 -1
- data/lib/expressir/model/declarations/type.rb +2 -1
- data/lib/expressir/model/identifier.rb +2 -1
- data/lib/expressir/model/literals/string.rb +2 -1
- data/lib/expressir/model/model_element.rb +84 -145
- data/lib/expressir/model/repository.rb +2 -1
- data/lib/expressir/schema_manifest.rb +150 -0
- data/lib/expressir/schema_manifest_entry.rb +17 -0
- data/lib/expressir/version.rb +1 -1
- data/lib/expressir.rb +29 -12
- metadata +5 -2
@@ -15,151 +15,83 @@ module Expressir
|
|
15
15
|
attribute :source, :string
|
16
16
|
attribute :untagged_remarks, :string, collection: true
|
17
17
|
|
18
|
-
|
18
|
+
POLYMORPHIC_CLASS_MAP = {
|
19
|
+
"Expressir::Model::Cache" => "Expressir::Model::Cache",
|
20
|
+
"Expressir::Model::Repository" => "Expressir::Model::Repository",
|
21
|
+
"Expressir::Model::DataTypes::Aggregate" => "Expressir::Model::DataTypes::Aggregate",
|
22
|
+
"Expressir::Model::DataTypes::Array" => "Expressir::Model::DataTypes::Array",
|
23
|
+
"Expressir::Model::DataTypes::Bag" => "Expressir::Model::DataTypes::Bag",
|
24
|
+
"Expressir::Model::DataTypes::Binary" => "Expressir::Model::DataTypes::Binary",
|
25
|
+
"Expressir::Model::DataTypes::Boolean" => "Expressir::Model::DataTypes::Boolean",
|
26
|
+
"Expressir::Model::DataTypes::EnumerationItem" => "Expressir::Model::DataTypes::EnumerationItem",
|
27
|
+
"Expressir::Model::DataTypes::Enumeration" => "Expressir::Model::DataTypes::Enumeration",
|
28
|
+
"Expressir::Model::DataTypes::GenericEntity" => "Expressir::Model::DataTypes::GenericEntity",
|
29
|
+
"Expressir::Model::DataTypes::Generic" => "Expressir::Model::DataTypes::Generic",
|
30
|
+
"Expressir::Model::DataTypes::Integer" => "Expressir::Model::DataTypes::Integer",
|
31
|
+
"Expressir::Model::DataTypes::List" => "Expressir::Model::DataTypes::List",
|
32
|
+
"Expressir::Model::DataTypes::Logical" => "Expressir::Model::DataTypes::Logical",
|
33
|
+
"Expressir::Model::DataTypes::Number" => "Expressir::Model::DataTypes::Number",
|
34
|
+
"Expressir::Model::DataTypes::Real" => "Expressir::Model::DataTypes::Real",
|
35
|
+
"Expressir::Model::DataTypes::Select" => "Expressir::Model::DataTypes::Select",
|
36
|
+
"Expressir::Model::DataTypes::Set" => "Expressir::Model::DataTypes::Set",
|
37
|
+
"Expressir::Model::DataTypes::String" => "Expressir::Model::DataTypes::String",
|
38
|
+
"Expressir::Model::Declarations::DerivedAttribute" => "Expressir::Model::Declarations::DerivedAttribute",
|
39
|
+
"Expressir::Model::Declarations::Attribute" => "Expressir::Model::Declarations::Attribute",
|
40
|
+
"Expressir::Model::Declarations::Constant" => "Expressir::Model::Declarations::Constant",
|
41
|
+
"Expressir::Model::Declarations::Entity" => "Expressir::Model::Declarations::Entity",
|
42
|
+
"Expressir::Model::Declarations::Function" => "Expressir::Model::Declarations::Function",
|
43
|
+
"Expressir::Model::Declarations::InterfaceItem" => "Expressir::Model::Declarations::InterfaceItem",
|
44
|
+
"Expressir::Model::Declarations::Interface" => "Expressir::Model::Declarations::Interface",
|
45
|
+
"Expressir::Model::Declarations::InterfacedItem" => "Expressir::Model::Declarations::InterfacedItem",
|
46
|
+
"Expressir::Model::Declarations::Parameter" => "Expressir::Model::Declarations::Parameter",
|
47
|
+
"Expressir::Model::Declarations::Procedure" => "Expressir::Model::Declarations::Procedure",
|
48
|
+
"Expressir::Model::Declarations::RemarkItem" => "Expressir::Model::Declarations::RemarkItem",
|
49
|
+
"Expressir::Model::Declarations::InformalPropositionRule" => "Expressir::Model::Declarations::InformalPropositionRule",
|
50
|
+
"Expressir::Model::Declarations::Rule" => "Expressir::Model::Declarations::Rule",
|
51
|
+
"Expressir::Model::Declarations::SchemaVersionItem" => "Expressir::Model::Declarations::SchemaVersionItem",
|
52
|
+
"Expressir::Model::Declarations::SchemaVersion" => "Expressir::Model::Declarations::SchemaVersion",
|
53
|
+
"Expressir::Model::Declarations::Schema" => "Expressir::Model::Declarations::Schema",
|
54
|
+
"Expressir::Model::Declarations::SubtypeConstraint" => "Expressir::Model::Declarations::SubtypeConstraint",
|
55
|
+
"Expressir::Model::Declarations::Type" => "Expressir::Model::Declarations::Type",
|
56
|
+
"Expressir::Model::Declarations::UniqueRule" => "Expressir::Model::Declarations::UniqueRule",
|
57
|
+
"Expressir::Model::Declarations::Variable" => "Expressir::Model::Declarations::Variable",
|
58
|
+
"Expressir::Model::Declarations::WhereRule" => "Expressir::Model::Declarations::WhereRule",
|
59
|
+
"Expressir::Model::Expressions::AggregateInitializerItem" => "Expressir::Model::Expressions::AggregateInitializerItem",
|
60
|
+
"Expressir::Model::Expressions::AggregateInitializer" => "Expressir::Model::Expressions::AggregateInitializer",
|
61
|
+
"Expressir::Model::Expressions::BinaryExpression" => "Expressir::Model::Expressions::BinaryExpression",
|
62
|
+
"Expressir::Model::Expressions::EntityConstructor" => "Expressir::Model::Expressions::EntityConstructor",
|
63
|
+
"Expressir::Model::Expressions::FunctionCall" => "Expressir::Model::Expressions::FunctionCall",
|
64
|
+
"Expressir::Model::Expressions::Interval" => "Expressir::Model::Expressions::Interval",
|
65
|
+
"Expressir::Model::Expressions::QueryExpression" => "Expressir::Model::Expressions::QueryExpression",
|
66
|
+
"Expressir::Model::Expressions::UnaryExpression" => "Expressir::Model::Expressions::UnaryExpression",
|
67
|
+
"Expressir::Model::Literals::Binary" => "Expressir::Model::Literals::Binary",
|
68
|
+
"Expressir::Model::Literals::Integer" => "Expressir::Model::Literals::Integer",
|
69
|
+
"Expressir::Model::Literals::Logical" => "Expressir::Model::Literals::Logical",
|
70
|
+
"Expressir::Model::Literals::Real" => "Expressir::Model::Literals::Real",
|
71
|
+
"Expressir::Model::Literals::String" => "Expressir::Model::Literals::String",
|
72
|
+
"Expressir::Model::References::AttributeReference" => "Expressir::Model::References::AttributeReference",
|
73
|
+
"Expressir::Model::References::GroupReference" => "Expressir::Model::References::GroupReference",
|
74
|
+
"Expressir::Model::References::IndexReference" => "Expressir::Model::References::IndexReference",
|
75
|
+
"Expressir::Model::References::SimpleReference" => "Expressir::Model::References::SimpleReference",
|
76
|
+
"Expressir::Model::Statements::Alias" => "Expressir::Model::Statements::Alias",
|
77
|
+
"Expressir::Model::Statements::Assignment" => "Expressir::Model::Statements::Assignment",
|
78
|
+
"Expressir::Model::Statements::CaseAction" => "Expressir::Model::Statements::CaseAction",
|
79
|
+
"Expressir::Model::Statements::Case" => "Expressir::Model::Statements::Case",
|
80
|
+
"Expressir::Model::Statements::Compound" => "Expressir::Model::Statements::Compound",
|
81
|
+
"Expressir::Model::Statements::Escape" => "Expressir::Model::Statements::Escape",
|
82
|
+
"Expressir::Model::Statements::If" => "Expressir::Model::Statements::If",
|
83
|
+
"Expressir::Model::Statements::Null" => "Expressir::Model::Statements::Null",
|
84
|
+
"Expressir::Model::Statements::ProcedureCall" => "Expressir::Model::Statements::ProcedureCall",
|
85
|
+
"Expressir::Model::Statements::Repeat" => "Expressir::Model::Statements::Repeat",
|
86
|
+
"Expressir::Model::Statements::Return" => "Expressir::Model::Statements::Return",
|
87
|
+
"Expressir::Model::Statements::Skip" => "Expressir::Model::Statements::Skip",
|
88
|
+
"Expressir::Model::SupertypeExpressions::BinarySupertypeExpression" => "Expressir::Model::SupertypeExpressions::BinarySupertypeExpression",
|
89
|
+
"Expressir::Model::SupertypeExpressions::OneofSupertypeExpression" => "Expressir::Model::SupertypeExpressions::OneofSupertypeExpression",
|
90
|
+
}.freeze
|
91
|
+
|
19
92
|
key_value do
|
20
93
|
map "_class", to: :_class, render_default: true,
|
21
|
-
polymorphic_map:
|
22
|
-
"Expressir::Model::Cache" =>
|
23
|
-
"Expressir::Model::Cache",
|
24
|
-
"Expressir::Model::Repository" =>
|
25
|
-
"Expressir::Model::Repository",
|
26
|
-
"Expressir::Model::DataTypes::Aggregate" =>
|
27
|
-
"Expressir::Model::DataTypes::Aggregate",
|
28
|
-
"Expressir::Model::DataTypes::Array" =>
|
29
|
-
"Expressir::Model::DataTypes::Array",
|
30
|
-
"Expressir::Model::DataTypes::Bag" =>
|
31
|
-
"Expressir::Model::DataTypes::Bag",
|
32
|
-
"Expressir::Model::DataTypes::Binary" =>
|
33
|
-
"Expressir::Model::DataTypes::Binary",
|
34
|
-
"Expressir::Model::DataTypes::Boolean" =>
|
35
|
-
"Expressir::Model::DataTypes::Boolean",
|
36
|
-
"Expressir::Model::DataTypes::EnumerationItem" =>
|
37
|
-
"Expressir::Model::DataTypes::EnumerationItem",
|
38
|
-
"Expressir::Model::DataTypes::Enumeration" =>
|
39
|
-
"Expressir::Model::DataTypes::Enumeration",
|
40
|
-
"Expressir::Model::DataTypes::GenericEntity" =>
|
41
|
-
"Expressir::Model::DataTypes::GenericEntity",
|
42
|
-
"Expressir::Model::DataTypes::Generic" =>
|
43
|
-
"Expressir::Model::DataTypes::Generic",
|
44
|
-
"Expressir::Model::DataTypes::Integer" =>
|
45
|
-
"Expressir::Model::DataTypes::Integer",
|
46
|
-
"Expressir::Model::DataTypes::List" =>
|
47
|
-
"Expressir::Model::DataTypes::List",
|
48
|
-
"Expressir::Model::DataTypes::Logical" =>
|
49
|
-
"Expressir::Model::DataTypes::Logical",
|
50
|
-
"Expressir::Model::DataTypes::Number" =>
|
51
|
-
"Expressir::Model::DataTypes::Number",
|
52
|
-
"Expressir::Model::DataTypes::Real" =>
|
53
|
-
"Expressir::Model::DataTypes::Real",
|
54
|
-
"Expressir::Model::DataTypes::Select" =>
|
55
|
-
"Expressir::Model::DataTypes::Select",
|
56
|
-
"Expressir::Model::DataTypes::Set" =>
|
57
|
-
"Expressir::Model::DataTypes::Set",
|
58
|
-
"Expressir::Model::DataTypes::String" =>
|
59
|
-
"Expressir::Model::DataTypes::String",
|
60
|
-
"Expressir::Model::Declarations::DerivedAttribute" =>
|
61
|
-
"Expressir::Model::Declarations::DerivedAttribute",
|
62
|
-
"Expressir::Model::Declarations::Attribute" =>
|
63
|
-
"Expressir::Model::Declarations::Attribute",
|
64
|
-
"Expressir::Model::Declarations::Constant" =>
|
65
|
-
"Expressir::Model::Declarations::Constant",
|
66
|
-
"Expressir::Model::Declarations::Entity" =>
|
67
|
-
"Expressir::Model::Declarations::Entity",
|
68
|
-
"Expressir::Model::Declarations::Function" =>
|
69
|
-
"Expressir::Model::Declarations::Function",
|
70
|
-
"Expressir::Model::Declarations::InterfaceItem" =>
|
71
|
-
"Expressir::Model::Declarations::InterfaceItem",
|
72
|
-
"Expressir::Model::Declarations::Interface" =>
|
73
|
-
"Expressir::Model::Declarations::Interface",
|
74
|
-
"Expressir::Model::Declarations::InterfacedItem" =>
|
75
|
-
"Expressir::Model::Declarations::InterfacedItem",
|
76
|
-
"Expressir::Model::Declarations::Parameter" =>
|
77
|
-
"Expressir::Model::Declarations::Parameter",
|
78
|
-
"Expressir::Model::Declarations::Procedure" =>
|
79
|
-
"Expressir::Model::Declarations::Procedure",
|
80
|
-
"Expressir::Model::Declarations::RemarkItem" =>
|
81
|
-
"Expressir::Model::Declarations::RemarkItem",
|
82
|
-
"Expressir::Model::Declarations::Rule" =>
|
83
|
-
"Expressir::Model::Declarations::Rule",
|
84
|
-
"Expressir::Model::Declarations::SchemaVersionItem" =>
|
85
|
-
"Expressir::Model::Declarations::SchemaVersionItem",
|
86
|
-
"Expressir::Model::Declarations::SchemaVersion" =>
|
87
|
-
"Expressir::Model::Declarations::SchemaVersion",
|
88
|
-
"Expressir::Model::Declarations::Schema" =>
|
89
|
-
"Expressir::Model::Declarations::Schema",
|
90
|
-
"Expressir::Model::Declarations::SubtypeConstraint" =>
|
91
|
-
"Expressir::Model::Declarations::SubtypeConstraint",
|
92
|
-
"Expressir::Model::Declarations::Type" =>
|
93
|
-
"Expressir::Model::Declarations::Type",
|
94
|
-
"Expressir::Model::Declarations::UniqueRule" =>
|
95
|
-
"Expressir::Model::Declarations::UniqueRule",
|
96
|
-
"Expressir::Model::Declarations::Variable" =>
|
97
|
-
"Expressir::Model::Declarations::Variable",
|
98
|
-
"Expressir::Model::Declarations::WhereRule" =>
|
99
|
-
"Expressir::Model::Declarations::WhereRule",
|
100
|
-
"Expressir::Model::Expressions::AggregateInitializerItem" =>
|
101
|
-
"Expressir::Model::Expressions::AggregateInitializerItem",
|
102
|
-
"Expressir::Model::Expressions::AggregateInitializer" =>
|
103
|
-
"Expressir::Model::Expressions::AggregateInitializer",
|
104
|
-
"Expressir::Model::Expressions::BinaryExpression" =>
|
105
|
-
"Expressir::Model::Expressions::BinaryExpression",
|
106
|
-
"Expressir::Model::Expressions::EntityConstructor" =>
|
107
|
-
"Expressir::Model::Expressions::EntityConstructor",
|
108
|
-
"Expressir::Model::Expressions::FunctionCall" =>
|
109
|
-
"Expressir::Model::Expressions::FunctionCall",
|
110
|
-
"Expressir::Model::Expressions::Interval" =>
|
111
|
-
"Expressir::Model::Expressions::Interval",
|
112
|
-
"Expressir::Model::Expressions::QueryExpression" =>
|
113
|
-
"Expressir::Model::Expressions::QueryExpression",
|
114
|
-
"Expressir::Model::Expressions::UnaryExpression" =>
|
115
|
-
"Expressir::Model::Expressions::UnaryExpression",
|
116
|
-
"Expressir::Model::Literals::Binary" =>
|
117
|
-
"Expressir::Model::Literals::Binary",
|
118
|
-
"Expressir::Model::Literals::Integer" =>
|
119
|
-
"Expressir::Model::Literals::Integer",
|
120
|
-
"Expressir::Model::Literals::Logical" =>
|
121
|
-
"Expressir::Model::Literals::Logical",
|
122
|
-
"Expressir::Model::Literals::Real" =>
|
123
|
-
"Expressir::Model::Literals::Real",
|
124
|
-
"Expressir::Model::Literals::String" =>
|
125
|
-
"Expressir::Model::Literals::String",
|
126
|
-
"Expressir::Model::References::AttributeReference" =>
|
127
|
-
"Expressir::Model::References::AttributeReference",
|
128
|
-
"Expressir::Model::References::GroupReference" =>
|
129
|
-
"Expressir::Model::References::GroupReference",
|
130
|
-
"Expressir::Model::References::IndexReference" =>
|
131
|
-
"Expressir::Model::References::IndexReference",
|
132
|
-
"Expressir::Model::References::SimpleReference" =>
|
133
|
-
"Expressir::Model::References::SimpleReference",
|
134
|
-
"Expressir::Model::Statements::Alias" =>
|
135
|
-
"Expressir::Model::Statements::Alias",
|
136
|
-
"Expressir::Model::Statements::Assignment" =>
|
137
|
-
"Expressir::Model::Statements::Assignment",
|
138
|
-
"Expressir::Model::Statements::CaseAction" =>
|
139
|
-
"Expressir::Model::Statements::CaseAction",
|
140
|
-
"Expressir::Model::Statements::Case" =>
|
141
|
-
"Expressir::Model::Statements::Case",
|
142
|
-
"Expressir::Model::Statements::Compound" =>
|
143
|
-
"Expressir::Model::Statements::Compound",
|
144
|
-
"Expressir::Model::Statements::Escape" =>
|
145
|
-
"Expressir::Model::Statements::Escape",
|
146
|
-
"Expressir::Model::Statements::If" =>
|
147
|
-
"Expressir::Model::Statements::If",
|
148
|
-
"Expressir::Model::Statements::Null" =>
|
149
|
-
"Expressir::Model::Statements::Null",
|
150
|
-
"Expressir::Model::Statements::ProcedureCall" =>
|
151
|
-
"Expressir::Model::Statements::ProcedureCall",
|
152
|
-
"Expressir::Model::Statements::Repeat" =>
|
153
|
-
"Expressir::Model::Statements::Repeat",
|
154
|
-
"Expressir::Model::Statements::Return" =>
|
155
|
-
"Expressir::Model::Statements::Return",
|
156
|
-
"Expressir::Model::Statements::Skip" =>
|
157
|
-
"Expressir::Model::Statements::Skip",
|
158
|
-
"Expressir::Model::SupertypeExpressions::BinarySupertypeExpression" =>
|
159
|
-
"Expressir::Model::SupertypeExpressions::BinarySupertypeExpression",
|
160
|
-
"Expressir::Model::SupertypeExpressions::OneofSupertypeExpression" =>
|
161
|
-
"Expressir::Model::SupertypeExpressions::OneofSupertypeExpression",
|
162
|
-
}
|
94
|
+
polymorphic_map: POLYMORPHIC_CLASS_MAP
|
163
95
|
end
|
164
96
|
|
165
97
|
def source
|
@@ -183,7 +115,12 @@ module Expressir
|
|
183
115
|
current_node = self
|
184
116
|
path_parts = []
|
185
117
|
loop do
|
186
|
-
|
118
|
+
# Skip adding the id if this is a RemarkItem that belongs to an InformalPropositionRule
|
119
|
+
# and has the same id as its parent
|
120
|
+
if !(current_node.is_a? References::SimpleReference) && current_node.class.method_defined?(:id) &&
|
121
|
+
!(is_a?(Declarations::RemarkItem) &&
|
122
|
+
parent.is_a?(Declarations::InformalPropositionRule) &&
|
123
|
+
id == parent.id)
|
187
124
|
path_parts << current_node.id
|
188
125
|
end
|
189
126
|
|
@@ -237,7 +174,9 @@ module Expressir
|
|
237
174
|
|
238
175
|
# @return [Hash<String, Declaration>]
|
239
176
|
def children_by_id
|
240
|
-
@children_by_id ||= children.select(&:id).
|
177
|
+
@children_by_id ||= children.select(&:id).to_h do |x|
|
178
|
+
[x.id.safe_downcase, x]
|
179
|
+
end
|
241
180
|
end
|
242
181
|
|
243
182
|
# @return [nil]
|
@@ -2,7 +2,8 @@ module Expressir
|
|
2
2
|
module Model
|
3
3
|
# Multi-schema global scope
|
4
4
|
class Repository < ModelElement
|
5
|
-
attribute :schemas, Expressir::Model::Declarations::Schema,
|
5
|
+
attribute :schemas, Expressir::Model::Declarations::Schema,
|
6
|
+
collection: true
|
6
7
|
attribute :_class, :string, default: -> { send(:name) }
|
7
8
|
|
8
9
|
key_value do
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lutaml/model"
|
4
|
+
require_relative "schema_manifest_entry"
|
5
|
+
|
6
|
+
module Expressir
|
7
|
+
class SchemaManifest < Lutaml::Model::Serializable
|
8
|
+
attribute :schemas, SchemaManifestEntry, collection: true,
|
9
|
+
initialize_empty: true
|
10
|
+
attribute :path, Lutaml::Model::Type::String
|
11
|
+
attr_accessor :output_path
|
12
|
+
|
13
|
+
def initialize(**args)
|
14
|
+
@path = path_relative_to_absolute(path) if path
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def base_path
|
19
|
+
File.dirname(@path)
|
20
|
+
end
|
21
|
+
|
22
|
+
yaml do
|
23
|
+
map "schemas", with: { from: :schemas_from_yaml, to: :schemas_to_yaml }
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_file(path)
|
27
|
+
from_yaml(File.read(path)).tap do |x|
|
28
|
+
x.set_initial_path(path)
|
29
|
+
end
|
30
|
+
rescue StandardError => e
|
31
|
+
raise InvalidSchemaManifestError, "Invalid schema manifest format: #{e.message}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_file(to_path = path)
|
35
|
+
FileUtils.mkdir_p(File.dirname(to_path))
|
36
|
+
File.write(to_path, to_yaml)
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_initial_path(new_path)
|
40
|
+
@path = path_relative_to_absolute(new_path)
|
41
|
+
schemas.each do |schema|
|
42
|
+
schema.path = path_relative_to_absolute(schema.path)
|
43
|
+
schema.container_path = File.expand_path(@path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def schemas_from_yaml(model, value)
|
48
|
+
model.schemas = value.map do |k, v|
|
49
|
+
SchemaManifestEntry.new(id: k,
|
50
|
+
path: path_relative_to_absolute(v["path"]))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def schemas_to_yaml(model, doc)
|
55
|
+
doc["schemas"] = model.schemas.sort_by(&:id).to_h do |schema|
|
56
|
+
# We are outputting the schemas collection file to the directory where
|
57
|
+
# the collection config is at (assumed to be Dir.pwd), not to the
|
58
|
+
# directory we sourced the manifest from, e.g.
|
59
|
+
# documents/iso-10303-41/schemas.yaml.
|
60
|
+
|
61
|
+
# So the schema.container_path = @config.path is not
|
62
|
+
# in fact needed, as the files are already absolute. This notion of
|
63
|
+
# using @path to create relative paths was misconceived
|
64
|
+
[
|
65
|
+
schema.id,
|
66
|
+
{
|
67
|
+
"path" => path_absolute_to_relative(
|
68
|
+
schema.path,
|
69
|
+
model.output_path || Dir.pwd,
|
70
|
+
),
|
71
|
+
},
|
72
|
+
]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def path_relative_to_absolute(relative_path)
|
77
|
+
eval_path = Pathname.new(relative_path)
|
78
|
+
return relative_path if eval_path.absolute?
|
79
|
+
|
80
|
+
# Or based on current working directory?
|
81
|
+
return relative_path unless @path
|
82
|
+
|
83
|
+
# ... but if this calculates path, we end up expanding it anyway
|
84
|
+
|
85
|
+
Pathname.new(File.dirname(@path)).join(eval_path).expand_path.to_s
|
86
|
+
end
|
87
|
+
|
88
|
+
def path_absolute_to_relative(absolute_path, container_path)
|
89
|
+
container_path ||= @path
|
90
|
+
return absolute_path unless container_path
|
91
|
+
|
92
|
+
p = Pathname.new(container_path)
|
93
|
+
container = p.directory? ? p.to_s : p.dirname
|
94
|
+
Pathname.new(absolute_path).relative_path_from(container).to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
def update_path(new_path)
|
98
|
+
if @path.nil?
|
99
|
+
@path = new_path
|
100
|
+
return @path
|
101
|
+
end
|
102
|
+
|
103
|
+
old_base_path = File.dirname(@path)
|
104
|
+
new_base_path = File.dirname(new_path)
|
105
|
+
update_schema_path(old_base_path, new_base_path)
|
106
|
+
|
107
|
+
@path = new_path
|
108
|
+
end
|
109
|
+
|
110
|
+
def concat(another_config)
|
111
|
+
unless another_config.is_a?(self.class)
|
112
|
+
raise StandardError,
|
113
|
+
"Can only concat a SchemaManifest object."
|
114
|
+
end
|
115
|
+
|
116
|
+
# We need to update the relative paths when paths exist
|
117
|
+
if path && another_config.path && path != another_config.path
|
118
|
+
new_config = another_config.dup
|
119
|
+
new_config.update_path(path)
|
120
|
+
end
|
121
|
+
|
122
|
+
schemas.concat(another_config.schemas)
|
123
|
+
end
|
124
|
+
|
125
|
+
def save_to_path(filename)
|
126
|
+
new_config = dup.tap do |c|
|
127
|
+
c.path = filename
|
128
|
+
c.update_path(File.dirname(filename))
|
129
|
+
c.output_path = filename
|
130
|
+
end
|
131
|
+
|
132
|
+
File.open(filename, "w") do |f|
|
133
|
+
puts "Writing #{filename}..."
|
134
|
+
f.write(new_config.to_yaml)
|
135
|
+
puts "Done."
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def update_schema_path(old_base_path, new_base_path)
|
140
|
+
schemas.each do |schema|
|
141
|
+
schema_path = Pathname.new(schema.path)
|
142
|
+
next if schema_path.absolute?
|
143
|
+
|
144
|
+
schema_path = (Pathname.new(old_base_path) + schema_path).cleanpath
|
145
|
+
# This is the new relative schema_path
|
146
|
+
schema.path = schema_path.relative_path_from(new_base_path)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lutaml/model"
|
4
|
+
|
5
|
+
module Expressir
|
6
|
+
class SchemaManifestEntry < Lutaml::Model::Serializable
|
7
|
+
attribute :id, Lutaml::Model::Type::String
|
8
|
+
attribute :path, Lutaml::Model::Type::String
|
9
|
+
# attribute :schemas_only, Lutaml::Model::Type::Boolean
|
10
|
+
|
11
|
+
# container_path is a copy of Expressir::SchemaManifest.path,
|
12
|
+
# used to resolve the path of each schema within
|
13
|
+
# Expressir::SchemaManifest.schemas,
|
14
|
+
# when Expressir::SchemaManifest.schemas is recursively flattened
|
15
|
+
attr_accessor :container_path
|
16
|
+
end
|
17
|
+
end
|
data/lib/expressir/version.rb
CHANGED
data/lib/expressir.rb
CHANGED
@@ -3,6 +3,8 @@ require_relative "expressir/cli"
|
|
3
3
|
require_relative "expressir/config"
|
4
4
|
require_relative "expressir/benchmark"
|
5
5
|
require_relative "expressir/coverage"
|
6
|
+
require_relative "expressir/schema_manifest"
|
7
|
+
require_relative "expressir/schema_manifest_entry"
|
6
8
|
require "lutaml/model"
|
7
9
|
require "liquid" # To enable Lutaml::Model::Liquefiable
|
8
10
|
|
@@ -27,6 +29,7 @@ end
|
|
27
29
|
|
28
30
|
module Expressir
|
29
31
|
class Error < StandardError; end
|
32
|
+
class InvalidSchemaManifestError < Error; end
|
30
33
|
|
31
34
|
def self.root
|
32
35
|
File.dirname(__dir__)
|
@@ -44,7 +47,8 @@ module Expressir
|
|
44
47
|
autoload :HyperlinkFormatter, "expressir/express/hyperlink_formatter"
|
45
48
|
autoload :ModelVisitor, "expressir/express/model_visitor"
|
46
49
|
autoload :Parser, "expressir/express/parser"
|
47
|
-
autoload :ResolveReferencesModelVisitor,
|
50
|
+
autoload :ResolveReferencesModelVisitor,
|
51
|
+
"expressir/express/resolve_references_model_visitor"
|
48
52
|
autoload :SchemaHeadFormatter, "expressir/express/schema_head_formatter"
|
49
53
|
autoload :Visitor, "expressir/express/visitor"
|
50
54
|
end
|
@@ -79,32 +83,42 @@ module Expressir
|
|
79
83
|
module Declarations
|
80
84
|
autoload :Attribute, "expressir/model/declarations/attribute"
|
81
85
|
autoload :Constant, "expressir/model/declarations/constant"
|
82
|
-
autoload :DerivedAttribute,
|
86
|
+
autoload :DerivedAttribute,
|
87
|
+
"expressir/model/declarations/derived_attribute"
|
83
88
|
autoload :Entity, "expressir/model/declarations/entity"
|
84
89
|
autoload :Function, "expressir/model/declarations/function"
|
85
90
|
autoload :Interface, "expressir/model/declarations/interface"
|
86
91
|
autoload :InterfaceItem, "expressir/model/declarations/interface_item"
|
87
92
|
autoload :InterfacedItem, "expressir/model/declarations/interfaced_item"
|
88
|
-
autoload :InverseAttribute,
|
93
|
+
autoload :InverseAttribute,
|
94
|
+
"expressir/model/declarations/inverse_attribute"
|
89
95
|
autoload :Parameter, "expressir/model/declarations/parameter"
|
90
96
|
autoload :Procedure, "expressir/model/declarations/procedure"
|
91
97
|
autoload :RemarkItem, "expressir/model/declarations/remark_item"
|
92
98
|
autoload :Rule, "expressir/model/declarations/rule"
|
93
99
|
autoload :Schema, "expressir/model/declarations/schema"
|
94
100
|
autoload :SchemaVersion, "expressir/model/declarations/schema_version"
|
95
|
-
autoload :SchemaVersionItem,
|
96
|
-
|
101
|
+
autoload :SchemaVersionItem,
|
102
|
+
"expressir/model/declarations/schema_version_item"
|
103
|
+
autoload :SubtypeConstraint,
|
104
|
+
"expressir/model/declarations/subtype_constraint"
|
97
105
|
autoload :Type, "expressir/model/declarations/type"
|
98
106
|
autoload :UniqueRule, "expressir/model/declarations/unique_rule"
|
99
107
|
autoload :Variable, "expressir/model/declarations/variable"
|
100
108
|
autoload :WhereRule, "expressir/model/declarations/where_rule"
|
109
|
+
autoload :InformalPropositionRule,
|
110
|
+
"expressir/model/declarations/informal_proposition_rule"
|
101
111
|
end
|
102
112
|
|
103
113
|
module Expressions
|
104
|
-
autoload :AggregateInitializer,
|
105
|
-
|
106
|
-
autoload :
|
107
|
-
|
114
|
+
autoload :AggregateInitializer,
|
115
|
+
"expressir/model/expressions/aggregate_initializer"
|
116
|
+
autoload :AggregateInitializerItem,
|
117
|
+
"expressir/model/expressions/aggregate_initializer_item"
|
118
|
+
autoload :BinaryExpression,
|
119
|
+
"expressir/model/expressions/binary_expression"
|
120
|
+
autoload :EntityConstructor,
|
121
|
+
"expressir/model/expressions/entity_constructor"
|
108
122
|
autoload :FunctionCall, "expressir/model/expressions/function_call"
|
109
123
|
autoload :Interval, "expressir/model/expressions/interval"
|
110
124
|
autoload :QueryExpression, "expressir/model/expressions/query_expression"
|
@@ -120,7 +134,8 @@ module Expressir
|
|
120
134
|
end
|
121
135
|
|
122
136
|
module References
|
123
|
-
autoload :AttributeReference,
|
137
|
+
autoload :AttributeReference,
|
138
|
+
"expressir/model/references/attribute_reference"
|
124
139
|
autoload :GroupReference, "expressir/model/references/group_reference"
|
125
140
|
autoload :IndexReference, "expressir/model/references/index_reference"
|
126
141
|
autoload :SimpleReference, "expressir/model/references/simple_reference"
|
@@ -142,8 +157,10 @@ module Expressir
|
|
142
157
|
end
|
143
158
|
|
144
159
|
module SupertypeExpressions
|
145
|
-
autoload :BinarySupertypeExpression,
|
146
|
-
|
160
|
+
autoload :BinarySupertypeExpression,
|
161
|
+
"expressir/model/supertype_expressions/binary_supertype_expression"
|
162
|
+
autoload :OneofSupertypeExpression,
|
163
|
+
"expressir/model/supertype_expressions/oneof_supertype_expression"
|
147
164
|
end
|
148
165
|
end
|
149
166
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expressir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- lib/expressir/model/declarations/derived_attribute.rb
|
215
215
|
- lib/expressir/model/declarations/entity.rb
|
216
216
|
- lib/expressir/model/declarations/function.rb
|
217
|
+
- lib/expressir/model/declarations/informal_proposition_rule.rb
|
217
218
|
- lib/expressir/model/declarations/interface.rb
|
218
219
|
- lib/expressir/model/declarations/interface_item.rb
|
219
220
|
- lib/expressir/model/declarations/interfaced_item.rb
|
@@ -264,6 +265,8 @@ files:
|
|
264
265
|
- lib/expressir/model/statements/skip.rb
|
265
266
|
- lib/expressir/model/supertype_expressions/binary_supertype_expression.rb
|
266
267
|
- lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb
|
268
|
+
- lib/expressir/schema_manifest.rb
|
269
|
+
- lib/expressir/schema_manifest_entry.rb
|
267
270
|
- lib/expressir/version.rb
|
268
271
|
homepage: https://github.com/lutaml/expressir
|
269
272
|
licenses:
|