expressir 2.4.34 → 2.4.35
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/lib/expressir/express/builder.rb +17 -5
- data/lib/expressir/express/builders/entity_decl_builder.rb +17 -5
- data/lib/expressir/express/formatters/declarations_formatter.rb +21 -14
- data/lib/expressir/express/pretty_formatter.rb +9 -14
- data/lib/expressir/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2fef762a5f189a2fa5e19af4e03b508ceecb9c51f4f70a805af7b0cfaa955c66
|
|
4
|
+
data.tar.gz: f4bfae05b286248e59f3bb54c83369c1c1bba957edeb5dc1e9e0aa8e7d0bc147
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75be497abf1fc565aa7098271d933715ab0e2ccaa2eed76eda589d37fe511cb8b52a2c08ffa537e23011cb847d14c9a9647c99e814473cdb5820577e61b31af1
|
|
7
|
+
data.tar.gz: 5420b2a0edfd9f4135515c75cf163b68dbb147e6b60fd7900528671862672f3695936884ea919692036c8e09eabb60f85c13cc939c61fdc67c9ec8ad2e1571cd
|
|
@@ -186,17 +186,29 @@ module Expressir
|
|
|
186
186
|
|
|
187
187
|
case item
|
|
188
188
|
when Array
|
|
189
|
-
item.each
|
|
190
|
-
result << build(sub) unless sub.nil?
|
|
191
|
-
end
|
|
189
|
+
item.each { |sub| append_built(result, build(sub)) unless sub.nil? }
|
|
192
190
|
else
|
|
193
|
-
|
|
194
|
-
result << built if built
|
|
191
|
+
append_built(result, build(item))
|
|
195
192
|
end
|
|
196
193
|
end
|
|
197
194
|
result
|
|
198
195
|
end
|
|
199
196
|
|
|
197
|
+
# Builders for list productions (ExplicitAttrBuilder and friends)
|
|
198
|
+
# return Arrays of nodes. Splice those items into the parent list
|
|
199
|
+
# rather than nesting them — nested Arrays break every consumer
|
|
200
|
+
# that expects ModelElements (`x.kind`, tree walks, formatters).
|
|
201
|
+
def append_built(result, built)
|
|
202
|
+
case built
|
|
203
|
+
when nil
|
|
204
|
+
nil
|
|
205
|
+
when Array
|
|
206
|
+
built.each { |b| append_built(result, b) }
|
|
207
|
+
else
|
|
208
|
+
result << built
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
200
212
|
# Fast build methods - call registered builder directly without hash wrapping
|
|
201
213
|
# These are optimized for hot paths in expression building
|
|
202
214
|
# NOTE: These assume data is already snake_case (no key conversion needed)
|
|
@@ -73,17 +73,17 @@ module Expressir
|
|
|
73
73
|
if entity_body.is_a?(Hash)
|
|
74
74
|
if entity_body[:explicit_attr]
|
|
75
75
|
explicit_attrs = Builder.build_children(entity_body[:explicit_attr])
|
|
76
|
-
attributes.concat(explicit_attrs)
|
|
76
|
+
attributes.concat(flatten_items(explicit_attrs))
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
if entity_body[:derive_clause]
|
|
80
80
|
derived = Builder.build({ derive_clause: entity_body[:derive_clause] })
|
|
81
|
-
attributes.
|
|
81
|
+
attributes.concat(flatten_items(derived))
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
if entity_body[:inverse_clause]
|
|
85
85
|
inverse = Builder.build({ inverse_clause: entity_body[:inverse_clause] })
|
|
86
|
-
attributes.
|
|
86
|
+
attributes.concat(flatten_items(inverse))
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
if entity_body[:unique_clause]
|
|
@@ -103,13 +103,25 @@ module Expressir
|
|
|
103
103
|
supertype_expression: supertype_expression,
|
|
104
104
|
subtype_of: subtype_of,
|
|
105
105
|
attributes: attributes,
|
|
106
|
-
unique_rules:
|
|
107
|
-
where_rules:
|
|
106
|
+
unique_rules: flatten_items(unique_rules),
|
|
107
|
+
where_rules: flatten_items(where_rules),
|
|
108
108
|
}
|
|
109
109
|
entity_params[:abstract] = true if abstract
|
|
110
110
|
|
|
111
111
|
Expressir::Model::Declarations::Entity.new(**entity_params)
|
|
112
112
|
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
# ExplicitAttrBuilder / DeriveClauseBuilder / InverseClauseBuilder
|
|
117
|
+
# return Arrays (one node per declaration). Call sites must splice
|
|
118
|
+
# those items into the parent list — nesting them leaves
|
|
119
|
+
# `entity.attributes` as Array-of-Array, which formatters then
|
|
120
|
+
# crash on (`undefined method 'kind' for an instance of Array`).
|
|
121
|
+
# lutaml-model 0.8.107 no longer flattens collection assignments.
|
|
122
|
+
def flatten_items(value)
|
|
123
|
+
Array(value).flatten.compact
|
|
124
|
+
end
|
|
113
125
|
end
|
|
114
126
|
end
|
|
115
127
|
end
|
|
@@ -110,20 +110,15 @@ module Expressir
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def format_declarations_entity(node)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
x.kind == Model::Declarations::Attribute::DERIVED
|
|
123
|
-
end
|
|
124
|
-
inverse_attributes = node.attributes.select do |x|
|
|
125
|
-
x.kind == Model::Declarations::Attribute::INVERSE
|
|
126
|
-
end
|
|
113
|
+
attrs = entity_attribute_items(node)
|
|
114
|
+
explicit_attributes = attrs.select do |x|
|
|
115
|
+
x.kind == Model::Declarations::Attribute::EXPLICIT
|
|
116
|
+
end
|
|
117
|
+
derived_attributes = attrs.select do |x|
|
|
118
|
+
x.kind == Model::Declarations::Attribute::DERIVED
|
|
119
|
+
end
|
|
120
|
+
inverse_attributes = attrs.select do |x|
|
|
121
|
+
x.kind == Model::Declarations::Attribute::INVERSE
|
|
127
122
|
end
|
|
128
123
|
|
|
129
124
|
indent_const = self.class.const_get(:INDENT)
|
|
@@ -231,6 +226,18 @@ module Expressir
|
|
|
231
226
|
].join("\n")
|
|
232
227
|
end
|
|
233
228
|
|
|
229
|
+
# Entity#attributes is the Ruby-parse layout (every attribute kind
|
|
230
|
+
# in one list). The core path parks derived/inverse in their own
|
|
231
|
+
# collections instead. Both may also arrive as Array-of-Array when
|
|
232
|
+
# a builder nested list productions. Normalize to a flat list of
|
|
233
|
+
# Attribute-like nodes before selecting on `kind`.
|
|
234
|
+
def entity_attribute_items(node)
|
|
235
|
+
items = Array(node.attributes)
|
|
236
|
+
items += Array(node.derived_attributes) if node.respond_to?(:derived_attributes)
|
|
237
|
+
items += Array(node.inverse_attributes) if node.respond_to?(:inverse_attributes)
|
|
238
|
+
items.flatten.compact.uniq(&:object_id)
|
|
239
|
+
end
|
|
240
|
+
|
|
234
241
|
def format_declarations_function(node)
|
|
235
242
|
indent_char = self.class.const_get(:INDENT_CHAR)
|
|
236
243
|
[
|
|
@@ -112,20 +112,15 @@ module Expressir
|
|
|
112
112
|
# @param node [Model::Declarations::Entity] Entity node
|
|
113
113
|
# @return [String] Formatted entity
|
|
114
114
|
def format_declarations_entity(node)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
x.kind == Model::Declarations::Attribute::DERIVED
|
|
125
|
-
end
|
|
126
|
-
inverse_attributes = node.attributes.select do |x|
|
|
127
|
-
x.kind == Model::Declarations::Attribute::INVERSE
|
|
128
|
-
end
|
|
115
|
+
attrs = entity_attribute_items(node)
|
|
116
|
+
explicit_attributes = attrs.select do |x|
|
|
117
|
+
x.kind == Model::Declarations::Attribute::EXPLICIT
|
|
118
|
+
end
|
|
119
|
+
derived_attributes = attrs.select do |x|
|
|
120
|
+
x.kind == Model::Declarations::Attribute::DERIVED
|
|
121
|
+
end
|
|
122
|
+
inverse_attributes = attrs.select do |x|
|
|
123
|
+
x.kind == Model::Declarations::Attribute::INVERSE
|
|
129
124
|
end
|
|
130
125
|
|
|
131
126
|
indent_str = " " * @config.indent
|
data/lib/expressir/version.rb
CHANGED