expressir 2.1.13 → 2.1.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.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +7 -82
  3. data/.rubocop_todo.yml +15 -74
  4. data/Gemfile +4 -5
  5. data/expressir.gemspec +3 -1
  6. data/lib/expressir/express/cache.rb +4 -6
  7. data/lib/expressir/express/formatter.rb +92 -63
  8. data/lib/expressir/express/model_visitor.rb +10 -9
  9. data/lib/expressir/express/parser.rb +10 -8
  10. data/lib/expressir/express/resolve_references_model_visitor.rb +0 -3
  11. data/lib/expressir/express/visitor.rb +2 -1
  12. data/lib/expressir/liquid.rb +0 -17
  13. data/lib/expressir/model/cache.rb +9 -8
  14. data/lib/expressir/model/data_types/aggregate.rb +6 -11
  15. data/lib/expressir/model/data_types/array.rb +14 -20
  16. data/lib/expressir/model/data_types/bag.rb +10 -14
  17. data/lib/expressir/model/data_types/binary.rb +8 -11
  18. data/lib/expressir/model/data_types/boolean.rb +6 -1
  19. data/lib/expressir/model/data_types/enumeration.rb +10 -14
  20. data/lib/expressir/model/data_types/enumeration_item.rb +3 -5
  21. data/lib/expressir/model/data_types/generic.rb +4 -6
  22. data/lib/expressir/model/data_types/generic_entity.rb +4 -6
  23. data/lib/expressir/model/data_types/integer.rb +6 -1
  24. data/lib/expressir/model/data_types/list.rb +12 -17
  25. data/lib/expressir/model/data_types/logical.rb +6 -1
  26. data/lib/expressir/model/data_types/number.rb +6 -1
  27. data/lib/expressir/model/data_types/real.rb +6 -8
  28. data/lib/expressir/model/data_types/select.rb +12 -17
  29. data/lib/expressir/model/data_types/set.rb +10 -14
  30. data/lib/expressir/model/data_types/string.rb +8 -11
  31. data/lib/expressir/model/declarations/attribute.rb +17 -26
  32. data/lib/expressir/model/declarations/constant.rb +8 -14
  33. data/lib/expressir/model/declarations/entity.rb +18 -29
  34. data/lib/expressir/model/declarations/function.rb +25 -39
  35. data/lib/expressir/model/declarations/interface.rb +12 -16
  36. data/lib/expressir/model/declarations/interface_item.rb +7 -11
  37. data/lib/expressir/model/declarations/interfaced_item.rb +11 -18
  38. data/lib/expressir/model/declarations/parameter.rb +8 -14
  39. data/lib/expressir/model/declarations/procedure.rb +23 -36
  40. data/lib/expressir/model/declarations/remark_item.rb +8 -11
  41. data/lib/expressir/model/declarations/rule.rb +27 -42
  42. data/lib/expressir/model/declarations/schema.rb +59 -58
  43. data/lib/expressir/model/declarations/schema_version.rb +7 -10
  44. data/lib/expressir/model/declarations/schema_version_item.rb +7 -10
  45. data/lib/expressir/model/declarations/subtype_constraint.rb +12 -20
  46. data/lib/expressir/model/declarations/type.rb +10 -17
  47. data/lib/expressir/model/declarations/unique_rule.rb +6 -11
  48. data/lib/expressir/model/declarations/variable.rb +8 -14
  49. data/lib/expressir/model/declarations/where_rule.rb +6 -11
  50. data/lib/expressir/model/expressions/aggregate_initializer.rb +6 -8
  51. data/lib/expressir/model/expressions/aggregate_initializer_item.rb +8 -11
  52. data/lib/expressir/model/expressions/binary_expression.rb +40 -42
  53. data/lib/expressir/model/expressions/entity_constructor.rb +8 -11
  54. data/lib/expressir/model/expressions/function_call.rb +8 -11
  55. data/lib/expressir/model/expressions/interval.rb +16 -22
  56. data/lib/expressir/model/expressions/query_expression.rb +8 -14
  57. data/lib/expressir/model/expressions/unary_expression.rb +11 -14
  58. data/lib/expressir/model/identifier.rb +8 -25
  59. data/lib/expressir/model/literals/binary.rb +6 -8
  60. data/lib/expressir/model/literals/integer.rb +6 -8
  61. data/lib/expressir/model/literals/logical.rb +9 -11
  62. data/lib/expressir/model/literals/real.rb +6 -8
  63. data/lib/expressir/model/literals/string.rb +8 -11
  64. data/lib/expressir/model/model_element.rb +164 -131
  65. data/lib/expressir/model/references/attribute_reference.rb +8 -11
  66. data/lib/expressir/model/references/group_reference.rb +8 -11
  67. data/lib/expressir/model/references/index_reference.rb +10 -14
  68. data/lib/expressir/model/references/simple_reference.rb +10 -13
  69. data/lib/expressir/model/repository.rb +5 -7
  70. data/lib/expressir/model/statements/alias.rb +8 -14
  71. data/lib/expressir/model/statements/assignment.rb +8 -11
  72. data/lib/expressir/model/statements/case.rb +10 -14
  73. data/lib/expressir/model/statements/case_action.rb +7 -10
  74. data/lib/expressir/model/statements/compound.rb +6 -8
  75. data/lib/expressir/model/statements/escape.rb +6 -1
  76. data/lib/expressir/model/statements/if.rb +10 -14
  77. data/lib/expressir/model/statements/null.rb +6 -1
  78. data/lib/expressir/model/statements/procedure_call.rb +8 -11
  79. data/lib/expressir/model/statements/repeat.rb +16 -26
  80. data/lib/expressir/model/statements/return.rb +6 -8
  81. data/lib/expressir/model/statements/skip.rb +6 -1
  82. data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +12 -16
  83. data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +6 -8
  84. data/lib/expressir/model.rb +1 -8
  85. data/lib/expressir/version.rb +1 -1
  86. data/lib/expressir.rb +7 -3
  87. metadata +32 -89
  88. data/lib/expressir/liquid/cache_drop.rb +0 -20
  89. data/lib/expressir/liquid/data_type_drop.rb +0 -8
  90. data/lib/expressir/liquid/data_types/aggregate_drop.rb +0 -21
  91. data/lib/expressir/liquid/data_types/array_drop.rb +0 -34
  92. data/lib/expressir/liquid/data_types/bag_drop.rb +0 -26
  93. data/lib/expressir/liquid/data_types/binary_drop.rb +0 -22
  94. data/lib/expressir/liquid/data_types/boolean_drop.rb +0 -10
  95. data/lib/expressir/liquid/data_types/enumeration_drop.rb +0 -30
  96. data/lib/expressir/liquid/data_types/enumeration_item_drop.rb +0 -17
  97. data/lib/expressir/liquid/data_types/generic_drop.rb +0 -17
  98. data/lib/expressir/liquid/data_types/generic_entity_drop.rb +0 -17
  99. data/lib/expressir/liquid/data_types/integer_drop.rb +0 -10
  100. data/lib/expressir/liquid/data_types/list_drop.rb +0 -30
  101. data/lib/expressir/liquid/data_types/logical_drop.rb +0 -10
  102. data/lib/expressir/liquid/data_types/number_drop.rb +0 -10
  103. data/lib/expressir/liquid/data_types/real_drop.rb +0 -18
  104. data/lib/expressir/liquid/data_types/select_drop.rb +0 -34
  105. data/lib/expressir/liquid/data_types/set_drop.rb +0 -26
  106. data/lib/expressir/liquid/data_types/string_drop.rb +0 -22
  107. data/lib/expressir/liquid/declaration_drop.rb +0 -8
  108. data/lib/expressir/liquid/declarations/attribute_drop.rb +0 -37
  109. data/lib/expressir/liquid/declarations/constant_drop.rb +0 -25
  110. data/lib/expressir/liquid/declarations/entity_drop.rb +0 -65
  111. data/lib/expressir/liquid/declarations/function_drop.rb +0 -93
  112. data/lib/expressir/liquid/declarations/interface_drop.rb +0 -30
  113. data/lib/expressir/liquid/declarations/interface_item_drop.rb +0 -22
  114. data/lib/expressir/liquid/declarations/interfaced_item_drop.rb +0 -34
  115. data/lib/expressir/liquid/declarations/parameter_drop.rb +0 -25
  116. data/lib/expressir/liquid/declarations/procedure_drop.rb +0 -89
  117. data/lib/expressir/liquid/declarations/remark_item_drop.rb +0 -22
  118. data/lib/expressir/liquid/declarations/rule_drop.rb +0 -105
  119. data/lib/expressir/liquid/declarations/schema_drop.rb +0 -131
  120. data/lib/expressir/liquid/declarations/schema_version_drop.rb +0 -26
  121. data/lib/expressir/liquid/declarations/schema_version_item_drop.rb +0 -22
  122. data/lib/expressir/liquid/declarations/subtype_constraint_drop.rb +0 -37
  123. data/lib/expressir/liquid/declarations/type_drop.rb +0 -37
  124. data/lib/expressir/liquid/declarations/unique_rule_drop.rb +0 -21
  125. data/lib/expressir/liquid/declarations/variable_drop.rb +0 -25
  126. data/lib/expressir/liquid/declarations/where_rule_drop.rb +0 -21
  127. data/lib/expressir/liquid/expression_drop.rb +0 -8
  128. data/lib/expressir/liquid/expressions/aggregate_initializer_drop.rb +0 -24
  129. data/lib/expressir/liquid/expressions/aggregate_initializer_item_drop.rb +0 -22
  130. data/lib/expressir/liquid/expressions/binary_expression_drop.rb +0 -26
  131. data/lib/expressir/liquid/expressions/entity_constructor_drop.rb +0 -26
  132. data/lib/expressir/liquid/expressions/function_call_drop.rb +0 -26
  133. data/lib/expressir/liquid/expressions/interval_drop.rb +0 -34
  134. data/lib/expressir/liquid/expressions/query_expression_drop.rb +0 -25
  135. data/lib/expressir/liquid/expressions/unary_expression_drop.rb +0 -22
  136. data/lib/expressir/liquid/identifier_drop.rb +0 -33
  137. data/lib/expressir/liquid/literal_drop.rb +0 -8
  138. data/lib/expressir/liquid/literals/binary_drop.rb +0 -18
  139. data/lib/expressir/liquid/literals/integer_drop.rb +0 -18
  140. data/lib/expressir/liquid/literals/logical_drop.rb +0 -18
  141. data/lib/expressir/liquid/literals/real_drop.rb +0 -18
  142. data/lib/expressir/liquid/literals/string_drop.rb +0 -22
  143. data/lib/expressir/liquid/model_element_drop.rb +0 -33
  144. data/lib/expressir/liquid/reference_drop.rb +0 -8
  145. data/lib/expressir/liquid/references/attribute_reference_drop.rb +0 -22
  146. data/lib/expressir/liquid/references/group_reference_drop.rb +0 -22
  147. data/lib/expressir/liquid/references/index_reference_drop.rb +0 -26
  148. data/lib/expressir/liquid/references/simple_reference_drop.rb +0 -22
  149. data/lib/expressir/liquid/repository_drop.rb +0 -25
  150. data/lib/expressir/liquid/statement_drop.rb +0 -8
  151. data/lib/expressir/liquid/statements/alias_drop.rb +0 -29
  152. data/lib/expressir/liquid/statements/assignment_drop.rb +0 -22
  153. data/lib/expressir/liquid/statements/case_action_drop.rb +0 -26
  154. data/lib/expressir/liquid/statements/case_drop.rb +0 -30
  155. data/lib/expressir/liquid/statements/compound_drop.rb +0 -22
  156. data/lib/expressir/liquid/statements/escape_drop.rb +0 -10
  157. data/lib/expressir/liquid/statements/if_drop.rb +0 -34
  158. data/lib/expressir/liquid/statements/null_drop.rb +0 -10
  159. data/lib/expressir/liquid/statements/procedure_call_drop.rb +0 -26
  160. data/lib/expressir/liquid/statements/repeat_drop.rb +0 -45
  161. data/lib/expressir/liquid/statements/return_drop.rb +0 -18
  162. data/lib/expressir/liquid/statements/skip_drop.rb +0 -10
  163. data/lib/expressir/liquid/supertype_expression_drop.rb +0 -8
  164. data/lib/expressir/liquid/supertype_expressions/binary_supertype_expression_drop.rb +0 -26
  165. data/lib/expressir/liquid/supertype_expressions/oneof_supertype_expression_drop.rb +0 -22
  166. data/lib/expressir/model/data_type.rb +0 -9
  167. data/lib/expressir/model/declaration.rb +0 -9
  168. data/lib/expressir/model/expression.rb +0 -9
  169. data/lib/expressir/model/literal.rb +0 -9
  170. data/lib/expressir/model/reference.rb +0 -9
  171. data/lib/expressir/model/statement.rb +0 -9
  172. data/lib/expressir/model/supertype_expression.rb +0 -9
@@ -3,18 +3,15 @@ module Expressir
3
3
  module Literals
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 7.5.4 String literal
6
- class String < Literal
7
- model_attr_accessor :value, "::String"
8
- model_attr_accessor :encoded, "::Boolean"
6
+ class String < ModelElement
7
+ attribute :value, :string
8
+ attribute :encoded, :boolean
9
+ attribute :_class, :string, default: -> { send(:name) }
9
10
 
10
- # @param [Hash] options
11
- # @option options [::String] :value
12
- # @option options [::Boolean] :encoded
13
- def initialize(options = {})
14
- @value = options[:value]
15
- @encoded = options[:encoded]
16
-
17
- super
11
+ key_value do
12
+ map "_class", to: :_class, render_default: true
13
+ map "value", to: :value, value_map: { to: { nil: :empty, empty: :empty } }
14
+ map "encoded", to: :encoded
18
15
  end
19
16
  end
20
17
  end
@@ -3,20 +3,169 @@ require "pathname"
3
3
  module Expressir
4
4
  module Model
5
5
  # Base model element
6
- class ModelElement
7
- CLASS_KEY = "_class".freeze
8
- FILE_KEY = "file".freeze
9
- SOURCE_KEY = "source".freeze
6
+ class ModelElement < Lutaml::Model::Serializable
7
+ SKIP_ATTRIBUTES = %i[parent _class].freeze
8
+ # :parent is a special attribute that is used to store the parent of the current element
9
+ # It is not a real attribute
10
+ # attribute :parent, ModelElement
11
+ attr_accessor :parent
10
12
 
11
- private_constant :CLASS_KEY
12
- private_constant :FILE_KEY
13
- private_constant :SOURCE_KEY
13
+ attribute :_class, :string, default: -> { send(:name) },
14
+ polymorphic_class: true
15
+ attribute :source, :string
16
+
17
+ # TODO: Add basic mappings that can be inherited by all subclasses
18
+ key_value do
19
+ map "_class", to: :_class, render_default: true,
20
+ polymorphic_map: {
21
+ "Expressir::Model::Cache" =>
22
+ "Expressir::Model::Cache",
23
+ "Expressir::Model::Repository" =>
24
+ "Expressir::Model::Repository",
25
+ "Expressir::Model::DataTypes::Aggregate" =>
26
+ "Expressir::Model::DataTypes::Aggregate",
27
+ "Expressir::Model::DataTypes::Array" =>
28
+ "Expressir::Model::DataTypes::Array",
29
+ "Expressir::Model::DataTypes::Bag" =>
30
+ "Expressir::Model::DataTypes::Bag",
31
+ "Expressir::Model::DataTypes::Binary" =>
32
+ "Expressir::Model::DataTypes::Binary",
33
+ "Expressir::Model::DataTypes::Boolean" =>
34
+ "Expressir::Model::DataTypes::Boolean",
35
+ "Expressir::Model::DataTypes::EnumerationItem" =>
36
+ "Expressir::Model::DataTypes::EnumerationItem",
37
+ "Expressir::Model::DataTypes::Enumeration" =>
38
+ "Expressir::Model::DataTypes::Enumeration",
39
+ "Expressir::Model::DataTypes::GenericEntity" =>
40
+ "Expressir::Model::DataTypes::GenericEntity",
41
+ "Expressir::Model::DataTypes::Generic" =>
42
+ "Expressir::Model::DataTypes::Generic",
43
+ "Expressir::Model::DataTypes::Integer" =>
44
+ "Expressir::Model::DataTypes::Integer",
45
+ "Expressir::Model::DataTypes::List" =>
46
+ "Expressir::Model::DataTypes::List",
47
+ "Expressir::Model::DataTypes::Logical" =>
48
+ "Expressir::Model::DataTypes::Logical",
49
+ "Expressir::Model::DataTypes::Number" =>
50
+ "Expressir::Model::DataTypes::Number",
51
+ "Expressir::Model::DataTypes::Real" =>
52
+ "Expressir::Model::DataTypes::Real",
53
+ "Expressir::Model::DataTypes::Select" =>
54
+ "Expressir::Model::DataTypes::Select",
55
+ "Expressir::Model::DataTypes::Set" =>
56
+ "Expressir::Model::DataTypes::Set",
57
+ "Expressir::Model::DataTypes::String" =>
58
+ "Expressir::Model::DataTypes::String",
59
+ "Expressir::Model::Declarations::Attribute" =>
60
+ "Expressir::Model::Declarations::Attribute",
61
+ "Expressir::Model::Declarations::Constant" =>
62
+ "Expressir::Model::Declarations::Constant",
63
+ "Expressir::Model::Declarations::Entity" =>
64
+ "Expressir::Model::Declarations::Entity",
65
+ "Expressir::Model::Declarations::Function" =>
66
+ "Expressir::Model::Declarations::Function",
67
+ "Expressir::Model::Declarations::InterfaceItem" =>
68
+ "Expressir::Model::Declarations::InterfaceItem",
69
+ "Expressir::Model::Declarations::Interface" =>
70
+ "Expressir::Model::Declarations::Interface",
71
+ "Expressir::Model::Declarations::InterfacedItem" =>
72
+ "Expressir::Model::Declarations::InterfacedItem",
73
+ "Expressir::Model::Declarations::Parameter" =>
74
+ "Expressir::Model::Declarations::Parameter",
75
+ "Expressir::Model::Declarations::Procedure" =>
76
+ "Expressir::Model::Declarations::Procedure",
77
+ "Expressir::Model::Declarations::RemarkItem" =>
78
+ "Expressir::Model::Declarations::RemarkItem",
79
+ "Expressir::Model::Declarations::Rule" =>
80
+ "Expressir::Model::Declarations::Rule",
81
+ "Expressir::Model::Declarations::SchemaVersionItem" =>
82
+ "Expressir::Model::Declarations::SchemaVersionItem",
83
+ "Expressir::Model::Declarations::SchemaVersion" =>
84
+ "Expressir::Model::Declarations::SchemaVersion",
85
+ "Expressir::Model::Declarations::Schema" =>
86
+ "Expressir::Model::Declarations::Schema",
87
+ "Expressir::Model::Declarations::SubtypeConstraint" =>
88
+ "Expressir::Model::Declarations::SubtypeConstraint",
89
+ "Expressir::Model::Declarations::Type" =>
90
+ "Expressir::Model::Declarations::Type",
91
+ "Expressir::Model::Declarations::UniqueRule" =>
92
+ "Expressir::Model::Declarations::UniqueRule",
93
+ "Expressir::Model::Declarations::Variable" =>
94
+ "Expressir::Model::Declarations::Variable",
95
+ "Expressir::Model::Declarations::WhereRule" =>
96
+ "Expressir::Model::Declarations::WhereRule",
97
+ "Expressir::Model::Expressions::AggregateInitializerItem" =>
98
+ "Expressir::Model::Expressions::AggregateInitializerItem",
99
+ "Expressir::Model::Expressions::AggregateInitializer" =>
100
+ "Expressir::Model::Expressions::AggregateInitializer",
101
+ "Expressir::Model::Expressions::BinaryExpression" =>
102
+ "Expressir::Model::Expressions::BinaryExpression",
103
+ "Expressir::Model::Expressions::EntityConstructor" =>
104
+ "Expressir::Model::Expressions::EntityConstructor",
105
+ "Expressir::Model::Expressions::FunctionCall" =>
106
+ "Expressir::Model::Expressions::FunctionCall",
107
+ "Expressir::Model::Expressions::Interval" =>
108
+ "Expressir::Model::Expressions::Interval",
109
+ "Expressir::Model::Expressions::QueryExpression" =>
110
+ "Expressir::Model::Expressions::QueryExpression",
111
+ "Expressir::Model::Expressions::UnaryExpression" =>
112
+ "Expressir::Model::Expressions::UnaryExpression",
113
+ "Expressir::Model::Literals::Binary" =>
114
+ "Expressir::Model::Literals::Binary",
115
+ "Expressir::Model::Literals::Integer" =>
116
+ "Expressir::Model::Literals::Integer",
117
+ "Expressir::Model::Literals::Logical" =>
118
+ "Expressir::Model::Literals::Logical",
119
+ "Expressir::Model::Literals::Real" =>
120
+ "Expressir::Model::Literals::Real",
121
+ "Expressir::Model::Literals::String" =>
122
+ "Expressir::Model::Literals::String",
123
+ "Expressir::Model::References::AttributeReference" =>
124
+ "Expressir::Model::References::AttributeReference",
125
+ "Expressir::Model::References::GroupReference" =>
126
+ "Expressir::Model::References::GroupReference",
127
+ "Expressir::Model::References::IndexReference" =>
128
+ "Expressir::Model::References::IndexReference",
129
+ "Expressir::Model::References::SimpleReference" =>
130
+ "Expressir::Model::References::SimpleReference",
131
+ "Expressir::Model::Statements::Alias" =>
132
+ "Expressir::Model::Statements::Alias",
133
+ "Expressir::Model::Statements::Assignment" =>
134
+ "Expressir::Model::Statements::Assignment",
135
+ "Expressir::Model::Statements::CaseAction" =>
136
+ "Expressir::Model::Statements::CaseAction",
137
+ "Expressir::Model::Statements::Case" =>
138
+ "Expressir::Model::Statements::Case",
139
+ "Expressir::Model::Statements::Compound" =>
140
+ "Expressir::Model::Statements::Compound",
141
+ "Expressir::Model::Statements::Escape" =>
142
+ "Expressir::Model::Statements::Escape",
143
+ "Expressir::Model::Statements::If" =>
144
+ "Expressir::Model::Statements::If",
145
+ "Expressir::Model::Statements::Null" =>
146
+ "Expressir::Model::Statements::Null",
147
+ "Expressir::Model::Statements::ProcedureCall" =>
148
+ "Expressir::Model::Statements::ProcedureCall",
149
+ "Expressir::Model::Statements::Repeat" =>
150
+ "Expressir::Model::Statements::Repeat",
151
+ "Expressir::Model::Statements::Return" =>
152
+ "Expressir::Model::Statements::Return",
153
+ "Expressir::Model::Statements::Skip" =>
154
+ "Expressir::Model::Statements::Skip",
155
+ "Expressir::Model::SupertypeExpressions::BinarySupertypeExpression" =>
156
+ "Expressir::Model::SupertypeExpressions::BinarySupertypeExpression",
157
+ "Expressir::Model::SupertypeExpressions::OneofSupertypeExpression" =>
158
+ "Expressir::Model::SupertypeExpressions::OneofSupertypeExpression",
159
+ }
160
+ end
14
161
 
15
- # @return [ModelElement]
16
- attr_accessor :parent
162
+ def source
163
+ Expressir::Express::Formatter.format(self)
164
+ end
17
165
 
18
166
  # @param [Hash] options
19
167
  def initialize(_options = {})
168
+ super
20
169
  attach_parent_to_children
21
170
  end
22
171
 
@@ -91,147 +240,31 @@ module Expressir
91
240
  nil
92
241
  end
93
242
 
94
- # @param [String] root_path
95
- # @param [Express::Formatter] formatter
96
- # @param [Boolean] include_empty
97
- # @param [Proc] select_proc
98
- # @return [Hash]
99
- def to_hash(root_path: nil, formatter: nil, include_empty: nil, select_proc: nil)
100
- # Filter out entries
101
- has_filter = !select_proc.nil? && select_proc.is_a?(Proc)
102
- return nil if has_filter && !select_proc.call(self)
103
-
104
- hash = {}
105
- hash[CLASS_KEY] = self.class.name
106
-
107
- self.class.model_attrs.each do |variable|
108
- value = send(variable)
109
- empty = value.nil? || (value.is_a?(Array) && value.count.zero?)
110
-
111
- # skip empty values
112
- next unless !empty || include_empty
113
-
114
- value_hash = case value
115
- when Array
116
- value.map do |v|
117
- if v.is_a? ModelElement
118
- v.to_hash(
119
- root_path: root_path,
120
- formatter: formatter,
121
- include_empty: include_empty,
122
- select_proc: select_proc,
123
- )
124
- else
125
- v
126
- end
127
- end.compact
128
- when ModelElement
129
- value.to_hash(
130
- root_path: root_path,
131
- formatter: formatter,
132
- include_empty: include_empty,
133
- select_proc: select_proc,
134
- )
135
- else
136
- value
137
- end
138
-
139
- hash[variable.to_s] = value_hash unless value_hash.nil?
140
- end
141
-
142
- if is_a?(Declarations::Schema) && file
143
- hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
144
- end
145
-
146
- if self.class.method_defined?(:source) && formatter
147
- hash[SOURCE_KEY] = formatter.format(self)
148
- end
149
-
150
- hash
151
- end
152
-
153
- # @return [Liquid::Drop]
154
- def to_liquid(options: nil)
155
- klass_name = "#{self.class.name.gsub('::Model::', '::Liquid::')}Drop"
156
- klass = Object.const_get(klass_name)
157
- klass.new(self, options: options)
158
- end
159
-
160
243
  def to_s(no_remarks: false, formatter: nil)
161
244
  f = formatter || Express::Formatter.new(no_remarks: no_remarks)
162
245
  f.no_remarks = no_remarks
163
246
  f.format(self)
164
247
  end
165
248
 
166
- # @param [Hash] hash
167
- # @param [String] root_path
168
- # @return [ModelElement]
169
- def self.from_hash(hash, root_path: nil)
170
- node_class = Object.const_get(hash[CLASS_KEY])
171
- node_options = {}
172
-
173
- node_class.model_attrs.each do |variable|
174
- value = hash[variable.to_s]
175
-
176
- node_options[variable] = case value
177
- when Array
178
- value.map do |value|
179
- if value.is_a? Hash
180
- from_hash(value, root_path: root_path)
181
- else
182
- value
183
- end
184
- end
185
- when Hash
186
- from_hash(value, root_path: root_path)
187
- else
188
- value
189
- end
190
- end
191
-
192
- if (node_class == Declarations::Schema) && hash[FILE_KEY]
193
- node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
194
- end
195
-
196
- node_class.new(node_options)
197
- end
198
-
199
- # @return [Array<Symbol>]
200
- def self.model_attrs
201
- @model_attrs ||= []
202
- end
203
-
204
- # Define a new model attribute
205
- # @param attr_name [Symbol] attribute name
206
- # @param attr_type [Symbol] attribute type
207
- # @!macro [attach] model_attr_accessor
208
- # @!attribute $1
209
- # @return [$2]
210
- def self.model_attr_accessor(attr_name, _attr_type = nil)
211
- @model_attrs ||= []
212
- @model_attrs << attr_name
213
-
214
- attr_accessor attr_name
215
- end
216
-
217
249
  private
218
250
 
219
251
  # @return [nil]
220
252
  def attach_parent_to_children
221
- self.class.model_attrs.each do |variable|
222
- value = send(variable)
253
+ self.class.attributes.each_pair do |symbol, _lutaml_attr|
254
+ value = send(symbol)
223
255
 
224
256
  case value
225
257
  when Array
226
- value.each do |value|
227
- if value.is_a? ModelElement
228
- value.parent = self
258
+ value.each do |val|
259
+ if val.is_a?(ModelElement)
260
+ val.parent = self
229
261
  end
230
262
  end
231
263
  when ModelElement
232
264
  value.parent = self
233
265
  end
234
266
  end
267
+
235
268
  nil
236
269
  end
237
270
  end
@@ -3,18 +3,15 @@ module Expressir
3
3
  module References
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 12.7.3 Attribute references
6
- class AttributeReference < Reference
7
- model_attr_accessor :ref, "Reference"
8
- model_attr_accessor :attribute, "Reference"
6
+ class AttributeReference < ModelElement
7
+ attribute :ref, ModelElement
8
+ attribute :attribute, ModelElement
9
+ attribute :_class, :string, default: -> { send(:name) }
9
10
 
10
- # @param [Hash] options
11
- # @option options [Reference] :ref
12
- # @option options [Reference] :attribute
13
- def initialize(options = {})
14
- @ref = options[:ref]
15
- @attribute = options[:attribute]
16
-
17
- super
11
+ key_value do
12
+ map "_class", to: :_class, render_default: true
13
+ map "ref", to: :ref
14
+ map "attribute", to: :attribute
18
15
  end
19
16
  end
20
17
  end
@@ -3,18 +3,15 @@ module Expressir
3
3
  module References
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 12.7.4 Group references
6
- class GroupReference < Reference
7
- model_attr_accessor :ref, "Reference"
8
- model_attr_accessor :entity, "Reference"
6
+ class GroupReference < ModelElement
7
+ attribute :ref, ModelElement
8
+ attribute :entity, ModelElement
9
+ attribute :_class, :string, default: -> { send(:name) }
9
10
 
10
- # @param [Hash] options
11
- # @option options [Reference] :ref
12
- # @option options [Reference] :entity
13
- def initialize(options = {})
14
- @ref = options[:ref]
15
- @entity = options[:entity]
16
-
17
- super
11
+ key_value do
12
+ map "_class", to: :_class, render_default: true
13
+ map "ref", to: :ref
14
+ map "entity", to: :entity
18
15
  end
19
16
  end
20
17
  end
@@ -5,21 +5,17 @@ module Expressir
5
5
  # - section 12.3.1 Binary indexing
6
6
  # - section 12.5.1 String indexing
7
7
  # - section 12.6.1 Aggregate indexing
8
- class IndexReference < Reference
9
- model_attr_accessor :ref, "Reference"
10
- model_attr_accessor :index1, "Expression"
11
- model_attr_accessor :index2, "Expression"
8
+ class IndexReference < ModelElement
9
+ attribute :ref, ModelElement
10
+ attribute :index1, ModelElement
11
+ attribute :index2, ModelElement
12
+ attribute :_class, :string, default: -> { send(:name) }
12
13
 
13
- # @param [Hash] options
14
- # @option options [Reference] :ref
15
- # @option options [Expression] :index1
16
- # @option options [Expression] :index2
17
- def initialize(options = {})
18
- @ref = options[:ref]
19
- @index1 = options[:index1]
20
- @index2 = options[:index2]
21
-
22
- super
14
+ key_value do
15
+ map "_class", to: :_class, render_default: true
16
+ map "ref", to: :ref
17
+ map "index1", to: :index1
18
+ map "index2", to: :index2
23
19
  end
24
20
  end
25
21
  end
@@ -3,20 +3,17 @@ module Expressir
3
3
  module References
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 12.7.1 Simple references
6
- class SimpleReference < Reference
7
- model_attr_accessor :id, "String"
6
+ class SimpleReference < ModelElement
7
+ attribute :id, :string
8
+ attribute :ref, ModelElement
9
+ attribute :base_path, :string
10
+ attribute :_class, :string, default: -> { send(:name) }
8
11
 
9
- model_attr_accessor :base_path, "String"
10
-
11
- # @param [Hash] options
12
- # @option options [String] :id
13
- # @option options [String] :base_path
14
- def initialize(options = {})
15
- @id = options[:id]
16
-
17
- @base_path = options[:base_path]
18
-
19
- super
12
+ key_value do
13
+ map "_class", to: :_class, render_default: true
14
+ map "id", to: :id
15
+ map "ref", to: :ref
16
+ map "base_path", to: :base_path
20
17
  end
21
18
  end
22
19
  end
@@ -2,14 +2,12 @@ module Expressir
2
2
  module Model
3
3
  # Multi-schema global scope
4
4
  class Repository < ModelElement
5
- model_attr_accessor :schemas, "Array<Declarations::Schema>"
5
+ attribute :schemas, Expressir::Model::Declarations::Schema, collection: true
6
+ attribute :_class, :string, default: -> { send(:name) }
6
7
 
7
- # @param [Hash] options
8
- # @option options [Array<Declarations::Schema>] :schemas
9
- def initialize(options = {})
10
- @schemas = options[:schemas] || []
11
-
12
- super
8
+ key_value do
9
+ map "_class", to: :_class, render_default: true
10
+ map "schemas", to: :schemas
13
11
  end
14
12
 
15
13
  # @return [Array<Declaration>]
@@ -3,23 +3,17 @@ module Expressir
3
3
  module Statements
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 13.2 Alias statement
6
- class Alias < Statement
6
+ class Alias < ModelElement
7
7
  include Identifier
8
8
 
9
- model_attr_accessor :expression, "Expression"
10
- model_attr_accessor :statements, "Array<Statement>"
9
+ attribute :expression, ModelElement
10
+ attribute :statements, ModelElement, collection: true
11
+ attribute :_class, :string, default: -> { send(:name) }
11
12
 
12
- # @param [Hash] options
13
- # @option (see Identifier#initialize_identifier)
14
- # @option options [Expression] :expression
15
- # @option options [Array<Statement>] :statements
16
- def initialize(options = {})
17
- initialize_identifier(options)
18
-
19
- @expression = options[:expression]
20
- @statements = options[:statements] || []
21
-
22
- super
13
+ key_value do
14
+ map "_class", to: :_class, render_default: true
15
+ map "expression", to: :expression
16
+ map "statements", to: :statements
23
17
  end
24
18
 
25
19
  # @return [Array<Declaration>]
@@ -3,18 +3,15 @@ module Expressir
3
3
  module Statements
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 13.3 Assignment
6
- class Assignment < Statement
7
- model_attr_accessor :ref, "Reference"
8
- model_attr_accessor :expression, "Expression"
6
+ class Assignment < ModelElement
7
+ attribute :ref, ModelElement
8
+ attribute :expression, ModelElement
9
+ attribute :_class, :string, default: -> { send(:name) }
9
10
 
10
- # @param [Hash] options
11
- # @option options [Reference] :ref
12
- # @option options [Expression] :expression
13
- def initialize(options = {})
14
- @ref = options[:ref]
15
- @expression = options[:expression]
16
-
17
- super
11
+ key_value do
12
+ map "_class", to: :_class, render_default: true
13
+ map "ref", to: :ref
14
+ map "expression", to: :expression
18
15
  end
19
16
  end
20
17
  end
@@ -3,21 +3,17 @@ module Expressir
3
3
  module Statements
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 13.4 Case statement
6
- class Case < Statement
7
- model_attr_accessor :expression, "Expression"
8
- model_attr_accessor :actions, "Array<CaseAction>"
9
- model_attr_accessor :otherwise_statement, "Statement"
6
+ class Case < ModelElement
7
+ attribute :expression, ModelElement
8
+ attribute :actions, CaseAction, collection: true
9
+ attribute :otherwise_statement, ModelElement
10
+ attribute :_class, :string, default: -> { send(:name) }
10
11
 
11
- # @param [Hash] options
12
- # @option options [Expression] :expression
13
- # @option options [Array<CaseAction>] :statements
14
- # @option options [Statement] :otherwise_statement
15
- def initialize(options = {})
16
- @expression = options[:expression]
17
- @actions = options[:actions] || []
18
- @otherwise_statement = options[:otherwise_statement]
19
-
20
- super
12
+ key_value do
13
+ map "_class", to: :_class, render_default: true
14
+ map "expression", to: :expression
15
+ map "actions", to: :actions
16
+ map "otherwise_statement", to: :otherwise_statement
21
17
  end
22
18
  end
23
19
  end
@@ -4,17 +4,14 @@ module Expressir
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 13.4 Case statement
6
6
  class CaseAction < ModelElement
7
- model_attr_accessor :labels, "Array<Expression>"
8
- model_attr_accessor :statement, "Statement"
7
+ attribute :labels, ModelElement, collection: true
8
+ attribute :statement, ModelElement
9
+ attribute :_class, :string, default: -> { send(:name) }
9
10
 
10
- # @param [Hash] options
11
- # @option options [Array<Expression>] :labels
12
- # @option options [Statement] :statement
13
- def initialize(options = {})
14
- @labels = options[:labels] || []
15
- @statement = options[:statement]
16
-
17
- super
11
+ key_value do
12
+ map "_class", to: :_class, render_default: true
13
+ map "labels", to: :labels
14
+ map "statement", to: :statement
18
15
  end
19
16
  end
20
17
  end
@@ -3,15 +3,13 @@ module Expressir
3
3
  module Statements
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 13.5 Compound statement
6
- class Compound < Statement
7
- model_attr_accessor :statements, "Array<Statement>"
6
+ class Compound < ModelElement
7
+ attribute :statements, ModelElement, collection: true
8
+ attribute :_class, :string, default: -> { send(:name) }
8
9
 
9
- # @param [Hash] options
10
- # @option options [Array<Statement>] :statements
11
- def initialize(options = {})
12
- @statements = options[:statements] || []
13
-
14
- super
10
+ key_value do
11
+ map "_class", to: :_class, render_default: true
12
+ map "statements", to: :statements
15
13
  end
16
14
  end
17
15
  end
@@ -3,7 +3,12 @@ module Expressir
3
3
  module Statements
4
4
  # Specified in ISO 10303-11:2004
5
5
  # - section 13.6 Escape statement
6
- class Escape < Statement
6
+ class Escape < ModelElement
7
+ attribute :_class, :string, default: -> { send(:name) }
8
+
9
+ key_value do
10
+ map "_class", to: :_class, render_default: true
11
+ end
7
12
  end
8
13
  end
9
14
  end