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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11ae98e1866bac67ff62c5a8f27abd2f06d94c62f8f7468c43d67554e1d4cd48
4
- data.tar.gz: a4ee98f12efb95ca5d3302aa8835120b2bad67ca37181430c9c4fcc1bbc8c561
3
+ metadata.gz: 2fef762a5f189a2fa5e19af4e03b508ceecb9c51f4f70a805af7b0cfaa955c66
4
+ data.tar.gz: f4bfae05b286248e59f3bb54c83369c1c1bba957edeb5dc1e9e0aa8e7d0bc147
5
5
  SHA512:
6
- metadata.gz: 0ec3c593547ace542482f7b5371d446dc7810e5e52f250281f0b5a6bca742d05c31abf15a8dc25456845314c98bdc673351a458a88384ea5e2d06b499904a411
7
- data.tar.gz: b2f7b4a8c851a61024baa8601c826c649bcff17393d91934a4faf5d75ee2ecf0936697bd5178a92dd36d3c850a809ac9c6ed39cf70fda3fb4aba3646698b65b8
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 do |sub|
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
- built = build(item)
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.push(derived) if derived
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.push(inverse) if inverse
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: [unique_rules].flatten,
107
- where_rules: [where_rules].flatten,
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
- if node.attributes.nil?
114
- explicit_attributes = []
115
- derived_attributes = []
116
- inverse_attributes = []
117
- else
118
- explicit_attributes = node.attributes.select do |x|
119
- x.kind == Model::Declarations::Attribute::EXPLICIT
120
- end
121
- derived_attributes = node.attributes.select do |x|
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
- if node.attributes.nil?
116
- explicit_attributes = []
117
- derived_attributes = []
118
- inverse_attributes = []
119
- else
120
- explicit_attributes = node.attributes.select do |x|
121
- x.kind == Model::Declarations::Attribute::EXPLICIT
122
- end
123
- derived_attributes = node.attributes.select do |x|
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
@@ -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.34".freeze
6
+ VERSION = "2.4.35".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.34
4
+ version: 2.4.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.