rgen_ext 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +9 -0
- data/lib/rgen/ext/comparison.rb +96 -0
- data/lib/rgen/ext/navigation_extensions.rb +61 -0
- data/lib/rgen/ext/version.rb +3 -0
- data/lib/rgen/ext.rb +3 -0
- data/rgen_ext.gemspec +26 -0
- data/test/helper.rb +8 -0
- data/test/test_comparison.rb +275 -0
- data/test/test_navigation_extensions.rb +144 -0
- data/test/test_traverse.rb +65 -0
- metadata +135 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
202
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Federico Tomassetti
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# RGen-Ext
|
2
|
+
|
3
|
+
We love RGen and use it over and over. Sometimes we feel there are some operations we implement ourself in different projects.
|
4
|
+
The maintainers of RGen want to keep the gem essential, so this project want to pack these common extensions which do not fit directly in RGen.
|
5
|
+
|
6
|
+
## Examples
|
7
|
+
|
8
|
+
### Comparison
|
9
|
+
|
10
|
+
There are two kinds of Comparator: a ShallowComparator (considering only attributes) and a DeepComparator (which considers also references, recursively).
|
11
|
+
You can use them like that:
|
12
|
+
|
13
|
+
include RGen::Ext::Comparison
|
14
|
+
|
15
|
+
ShallowComparator.eql?(ferrari_enzo,ferrari_superenzo)
|
16
|
+
DeepComparator.eql?(ferrari_enzo,ferrari_superenzo)
|
17
|
+
|
18
|
+
### Navigation
|
19
|
+
|
20
|
+
Do you feel that the RGen objects should be able to give a list of all their children (direct and indirect)?
|
21
|
+
In RGen-ext you do that in this way:
|
22
|
+
|
23
|
+
class AddressBook < RGen::MetamodelBuilder::MMBase
|
24
|
+
include RGen::Ext::NavigationExtensions
|
25
|
+
contains_many_uni 'entries', AddressBookEntry
|
26
|
+
end
|
27
|
+
|
28
|
+
jones_address_book.all_children # this returnes all entries
|
29
|
+
jones_address_book.all_children_deep # this returns all entries and all the children of all entries and so on
|
30
|
+
|
31
|
+
It is also possible to iterate among all the children and the children of the children and so on. Quite handy when you have to traverse a tree:
|
32
|
+
|
33
|
+
jones_address_book.traverse {|n| puts "Traversing #{n}" }
|
34
|
+
|
35
|
+
You have to add the extension only on the classes on which you want to invoke these methods directly, not necessarily on all the classes of the hierarchy.
|
36
|
+
|
37
|
+
### Other stuff
|
38
|
+
|
39
|
+
For that I am looking for YOUR contributions!
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
gem 'rgen_ext'
|
46
|
+
|
47
|
+
And then execute:
|
48
|
+
|
49
|
+
$ bundle
|
50
|
+
|
51
|
+
Or install it yourself as:
|
52
|
+
|
53
|
+
$ gem install rgen_ext
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
I am really open to contributions and I would revise them fast and include them even faster, so just start write them.
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# RGen-ext
|
2
|
+
# Common extension to the RGen Framework
|
3
|
+
# Federico Tomassetti, 2013
|
4
|
+
|
5
|
+
module RGen
|
6
|
+
module Ext
|
7
|
+
module Comparison
|
8
|
+
|
9
|
+
module UnorderedComparison
|
10
|
+
|
11
|
+
def self.eql?(left,right,element_comparator)
|
12
|
+
return false unless left.count==right.count
|
13
|
+
left.each do |l|
|
14
|
+
return false unless how_many_times_in(l,left,element_comparator)==how_many_times_in(l,right,element_comparator)
|
15
|
+
end
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.how_many_times_in(el,array,element_comparator)
|
22
|
+
count = 0
|
23
|
+
array.each do |other|
|
24
|
+
if element_comparator
|
25
|
+
count += 1 if element_comparator.eql?(el,other)
|
26
|
+
else
|
27
|
+
count += 1 if el.eql?(other)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
count
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
module ShallowComparator
|
36
|
+
|
37
|
+
# It does not check references, so that infinite recursion
|
38
|
+
# is avoided
|
39
|
+
def self.eql?(left,right)
|
40
|
+
return false if right==nil
|
41
|
+
return false unless left.class==right.class
|
42
|
+
left.class.ecore.eAllAttributes.each do |attribute|
|
43
|
+
raise "Attrib <nil> for class #{left.class.ecore.name}" unless attribute
|
44
|
+
left_value = left.send(attribute.name)
|
45
|
+
right_value = right.send(attribute.name)
|
46
|
+
if (!attribute.many) || attribute.ordered
|
47
|
+
return false unless left_value.eql?(right_value)
|
48
|
+
else
|
49
|
+
return false unless UnorderedComparison.eql?(left_value,right_value,nil)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
module DeepComparator
|
58
|
+
|
59
|
+
# It checks all the containment references recursively
|
60
|
+
# while it compare the non-containment references using
|
61
|
+
# ShallowComparator, to avoid infinite recursion
|
62
|
+
def self.eql?(left,right)
|
63
|
+
return false unless ShallowComparator.eql?(left,right)
|
64
|
+
left.class.ecore.eAllReferences.each do |ref|
|
65
|
+
left_value = left.send(ref.name)
|
66
|
+
right_value = right.send(ref.name)
|
67
|
+
# it should ignore relations which has as opposite a containment
|
68
|
+
unless (ref.getEOpposite and ref.getEOpposite.containment)
|
69
|
+
comparison_method = ref.containment ? DeepComparator : ShallowComparator
|
70
|
+
if left_value==nil || right_value==nil
|
71
|
+
# if one value is nil, both should be nil
|
72
|
+
return false unless left_value==right_value
|
73
|
+
elsif ref.many
|
74
|
+
# compare each children
|
75
|
+
return false unless left_value.count==right_value.count
|
76
|
+
if ref.ordered
|
77
|
+
for i in 0...left_value.count
|
78
|
+
return false unless comparison_method.send(:eql?,left_value[i],right_value[i])
|
79
|
+
end
|
80
|
+
else
|
81
|
+
return false unless UnorderedComparison.eql?(left_value,right_value,DeepComparator)
|
82
|
+
end
|
83
|
+
else
|
84
|
+
# compare the only child
|
85
|
+
return false unless comparison_method.send(:eql?,left_value,right_value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# RGen-ext
|
2
|
+
# Common extension to the RGen Framework
|
3
|
+
# Federico Tomassetti, 2013
|
4
|
+
|
5
|
+
module RGen
|
6
|
+
module Ext
|
7
|
+
|
8
|
+
# This module is intended to be included in a class extending MMBase
|
9
|
+
# to plug-in additional functionalities to navigate the model
|
10
|
+
#
|
11
|
+
# The methods use a parameter is used to make the method
|
12
|
+
# work on elements of the subtree which do not include
|
13
|
+
# this module
|
14
|
+
module NavigationExtensions
|
15
|
+
|
16
|
+
# Return the root of the model
|
17
|
+
def root(of=self)
|
18
|
+
return of unless of.eContainer
|
19
|
+
root(of.eContainer)
|
20
|
+
end
|
21
|
+
|
22
|
+
def all_children(of=self)
|
23
|
+
arr = []
|
24
|
+
ecore = of.class.ecore
|
25
|
+
ecore.eAllReferences.select {|r| r.containment}.each do |ref|
|
26
|
+
res = of.send(ref.name.to_sym)
|
27
|
+
if ref.many
|
28
|
+
res.each do |el|
|
29
|
+
arr << el unless el==nil
|
30
|
+
end
|
31
|
+
elsif res!=nil
|
32
|
+
arr << res
|
33
|
+
end
|
34
|
+
end
|
35
|
+
arr
|
36
|
+
end
|
37
|
+
|
38
|
+
def all_children_deep(of=self)
|
39
|
+
arr = []
|
40
|
+
of.all_children.each do |c|
|
41
|
+
arr << c
|
42
|
+
c.all_children_deep.each do |cc|
|
43
|
+
arr << cc
|
44
|
+
end
|
45
|
+
end
|
46
|
+
arr
|
47
|
+
end
|
48
|
+
|
49
|
+
# The node itself and all the node in the sub-tree
|
50
|
+
# are passed to the given block
|
51
|
+
def traverse(&op)
|
52
|
+
op.call(self)
|
53
|
+
all_children_deep.each do |c|
|
54
|
+
op.call(c)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/rgen/ext.rb
ADDED
data/rgen_ext.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rgen/ext/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rgen_ext"
|
8
|
+
spec.version = RgenExt::VERSION
|
9
|
+
spec.authors = ["Federico Tomassetti"]
|
10
|
+
spec.email = ["f.tomassetti@gmail.com"]
|
11
|
+
spec.description = %q{Extensions of general use to RGen}
|
12
|
+
spec.summary = %q{Extensions of general use to RGen}
|
13
|
+
spec.homepage = "http://github.com/ftomassetti/rgen_ext"
|
14
|
+
spec.license = "Apache License v2"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rgen"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ComparisonTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include RGen::Ext::Comparison
|
6
|
+
|
7
|
+
module OrderedTestMetamodel
|
8
|
+
|
9
|
+
class Address < RGen::MetamodelBuilder::MMBase
|
10
|
+
has_attr 'type', String
|
11
|
+
has_attr 'street', String
|
12
|
+
has_attr 'number', String
|
13
|
+
end
|
14
|
+
|
15
|
+
class AddressBookEntry < RGen::MetamodelBuilder::MMBase
|
16
|
+
has_attr 'name', String
|
17
|
+
contains_many_uni 'addresses', Address
|
18
|
+
end
|
19
|
+
|
20
|
+
class AddressBook < RGen::MetamodelBuilder::MMBase
|
21
|
+
contains_many_uni 'entries', AddressBookEntry
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
module UnorderedTestMetamodel
|
27
|
+
|
28
|
+
class Country < RGen::MetamodelBuilder::MMBase
|
29
|
+
has_many_attr 'qualities', String, ordered: false
|
30
|
+
end
|
31
|
+
|
32
|
+
class World < RGen::MetamodelBuilder::MMBase
|
33
|
+
contains_many_uni 'countries', Country, ordered: false
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
module CarMetamodel
|
39
|
+
|
40
|
+
class Engine < RGen::MetamodelBuilder::MMBase
|
41
|
+
has_attr 'code',String
|
42
|
+
has_attr 'horse_power',Integer
|
43
|
+
end
|
44
|
+
|
45
|
+
class Car < RGen::MetamodelBuilder::MMBase
|
46
|
+
contains_one_uni 'engine', Engine
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup
|
52
|
+
# Ordered data
|
53
|
+
|
54
|
+
@jones_work_address = OrderedTestMetamodel::Address.new
|
55
|
+
@jones_work_address.type = 'work'
|
56
|
+
|
57
|
+
@jones_home_address = OrderedTestMetamodel::Address.new
|
58
|
+
@jones_home_address.type = 'home'
|
59
|
+
|
60
|
+
@jones_book_entry = OrderedTestMetamodel::AddressBookEntry.new
|
61
|
+
@jones_book_entry.name = 'Mr. Jones'
|
62
|
+
@jones_book_entry.addAddresses(@jones_work_address)
|
63
|
+
@jones_book_entry.addAddresses(@jones_home_address)
|
64
|
+
|
65
|
+
@smith_shop_address = OrderedTestMetamodel::Address.new
|
66
|
+
@smith_shop_address.type = 'shop'
|
67
|
+
|
68
|
+
@smith_home_address = OrderedTestMetamodel::Address.new
|
69
|
+
@smith_home_address.type = 'home'
|
70
|
+
|
71
|
+
@smith_book_entry = OrderedTestMetamodel::AddressBookEntry.new
|
72
|
+
@smith_book_entry.name = 'Mr. Smith'
|
73
|
+
@smith_book_entry.addAddresses(@smith_shop_address)
|
74
|
+
@smith_book_entry.addAddresses(@smith_home_address)
|
75
|
+
|
76
|
+
@green_book_entry = OrderedTestMetamodel::AddressBookEntry.new
|
77
|
+
@green_book_entry.name = 'Mr. Green'
|
78
|
+
|
79
|
+
@address_book_1 = OrderedTestMetamodel::AddressBook.new
|
80
|
+
@address_book_1.addEntries(@jones_book_entry)
|
81
|
+
@address_book_1.addEntries(@smith_book_entry)
|
82
|
+
@address_book_1.addEntries(@green_book_entry)
|
83
|
+
|
84
|
+
# Unordered data
|
85
|
+
|
86
|
+
@c_1 = UnorderedTestMetamodel::Country.new
|
87
|
+
@c_1.addQualities 'sunny'
|
88
|
+
@c_1.addQualities 'open-minded'
|
89
|
+
|
90
|
+
@c_2 = UnorderedTestMetamodel::Country.new
|
91
|
+
@c_2.addQualities 'open-minded'
|
92
|
+
@c_2.addQualities 'sunny'
|
93
|
+
|
94
|
+
@c_3 = UnorderedTestMetamodel::Country.new
|
95
|
+
@c_3.addQualities 'open-minded'
|
96
|
+
@c_3.addQualities 'sunny'
|
97
|
+
@c_3.addQualities 'sunny'
|
98
|
+
|
99
|
+
@c_4 = UnorderedTestMetamodel::Country.new
|
100
|
+
@c_4.addQualities 'open-minded'
|
101
|
+
@c_4.addQualities 'open-minded'
|
102
|
+
|
103
|
+
@world_1 = UnorderedTestMetamodel::World.new
|
104
|
+
@world_1.addCountries @c_1
|
105
|
+
@world_1.addCountries @c_2
|
106
|
+
@world_1.addCountries @c_3
|
107
|
+
|
108
|
+
@world_2 = UnorderedTestMetamodel::World.new
|
109
|
+
@world_2.addCountries @c_2
|
110
|
+
@world_2.addCountries @c_1
|
111
|
+
@world_2.addCountries @c_3
|
112
|
+
|
113
|
+
@world_3 = UnorderedTestMetamodel::World.new
|
114
|
+
@world_3.addCountries @c_3
|
115
|
+
@world_3.addCountries @c_1
|
116
|
+
@world_3.addCountries @c_2
|
117
|
+
|
118
|
+
@world_4 = UnorderedTestMetamodel::World.new
|
119
|
+
@world_4.addCountries @c_2
|
120
|
+
@world_4.addCountries @c_1
|
121
|
+
@world_4.addCountries @c_2
|
122
|
+
|
123
|
+
# Car test data
|
124
|
+
@ferrari_v8 = CarMetamodel::Engine.new({:horse_power => 800, :code => 'Ferrari-V8'})
|
125
|
+
@ferrari_enzo = CarMetamodel::Car.new
|
126
|
+
@ferrari_enzo.engine = @ferrari_v8
|
127
|
+
|
128
|
+
@ferrari_v8b = CarMetamodel::Engine.new({:horse_power => 800, :code => 'Ferrari-V8'})
|
129
|
+
@ferrari_superenzo = CarMetamodel::Car.new
|
130
|
+
@ferrari_superenzo.engine = @ferrari_v8b
|
131
|
+
|
132
|
+
@ferrari_v9 = CarMetamodel::Engine.new({:horse_power => 900, :code => 'Ferrari-V9'})
|
133
|
+
@ferrari_superextraenzo = CarMetamodel::Car.new
|
134
|
+
@ferrari_superextraenzo.engine = @ferrari_v9
|
135
|
+
|
136
|
+
@auto_without_engine = CarMetamodel::Car.new
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_deep_comparator_based_on_unordered_attributes
|
140
|
+
assert_equal true, DeepComparator.eql?(@c_1,@c_1)
|
141
|
+
assert_equal true, DeepComparator.eql?(@c_1,@c_2)
|
142
|
+
assert_equal false,DeepComparator.eql?(@c_1,@c_3)
|
143
|
+
assert_equal false,DeepComparator.eql?(@c_1,@c_4)
|
144
|
+
assert_equal true, DeepComparator.eql?(@c_2,@c_1)
|
145
|
+
assert_equal true, DeepComparator.eql?(@c_2,@c_2)
|
146
|
+
assert_equal false,DeepComparator.eql?(@c_2,@c_3)
|
147
|
+
assert_equal false,DeepComparator.eql?(@c_2,@c_4)
|
148
|
+
assert_equal false,DeepComparator.eql?(@c_3,@c_1)
|
149
|
+
assert_equal false,DeepComparator.eql?(@c_3,@c_2)
|
150
|
+
assert_equal true, DeepComparator.eql?(@c_3,@c_3)
|
151
|
+
assert_equal false,DeepComparator.eql?(@c_3,@c_4)
|
152
|
+
assert_equal false,DeepComparator.eql?(@c_4,@c_1)
|
153
|
+
assert_equal false,DeepComparator.eql?(@c_4,@c_2)
|
154
|
+
assert_equal false,DeepComparator.eql?(@c_4,@c_3)
|
155
|
+
assert_equal true, DeepComparator.eql?(@c_4,@c_4)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_shallow_comparator_based_on_unordered_attributes
|
159
|
+
assert_equal true, ShallowComparator.eql?(@c_1,@c_1)
|
160
|
+
assert_equal true, ShallowComparator.eql?(@c_1,@c_2)
|
161
|
+
assert_equal false,ShallowComparator.eql?(@c_1,@c_3)
|
162
|
+
assert_equal false,ShallowComparator.eql?(@c_1,@c_4)
|
163
|
+
assert_equal true, ShallowComparator.eql?(@c_2,@c_1)
|
164
|
+
assert_equal true, ShallowComparator.eql?(@c_2,@c_2)
|
165
|
+
assert_equal false,ShallowComparator.eql?(@c_2,@c_3)
|
166
|
+
assert_equal false,ShallowComparator.eql?(@c_2,@c_4)
|
167
|
+
assert_equal false,ShallowComparator.eql?(@c_3,@c_1)
|
168
|
+
assert_equal false,ShallowComparator.eql?(@c_3,@c_2)
|
169
|
+
assert_equal true, ShallowComparator.eql?(@c_3,@c_3)
|
170
|
+
assert_equal false,ShallowComparator.eql?(@c_3,@c_4)
|
171
|
+
assert_equal false,ShallowComparator.eql?(@c_4,@c_1)
|
172
|
+
assert_equal false,ShallowComparator.eql?(@c_4,@c_2)
|
173
|
+
assert_equal false,ShallowComparator.eql?(@c_4,@c_3)
|
174
|
+
assert_equal true, ShallowComparator.eql?(@c_4,@c_4)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_deep_comparator_based_on_unordered_references
|
178
|
+
assert_equal true, DeepComparator.eql?(@world_1,@world_1)
|
179
|
+
assert_equal true, DeepComparator.eql?(@world_1,@world_2)
|
180
|
+
assert_equal true, DeepComparator.eql?(@world_1,@world_3)
|
181
|
+
assert_equal false, DeepComparator.eql?(@world_1,@world_4)
|
182
|
+
assert_equal true, DeepComparator.eql?(@world_2,@world_1)
|
183
|
+
assert_equal true, DeepComparator.eql?(@world_2,@world_2)
|
184
|
+
assert_equal true, DeepComparator.eql?(@world_2,@world_3)
|
185
|
+
assert_equal false, DeepComparator.eql?(@world_2,@world_4)
|
186
|
+
assert_equal true, DeepComparator.eql?(@world_3,@world_1)
|
187
|
+
assert_equal true, DeepComparator.eql?(@world_3,@world_2)
|
188
|
+
assert_equal true, DeepComparator.eql?(@world_3,@world_3)
|
189
|
+
assert_equal false, DeepComparator.eql?(@world_3,@world_4)
|
190
|
+
assert_equal false, DeepComparator.eql?(@world_4,@world_1)
|
191
|
+
assert_equal false, DeepComparator.eql?(@world_4,@world_2)
|
192
|
+
assert_equal false, DeepComparator.eql?(@world_4,@world_3)
|
193
|
+
assert_equal true, DeepComparator.eql?(@world_4,@world_4)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_deep_comparator_based_on_ordered_attributes_positive_case
|
197
|
+
same_as_jones_work_address = OrderedTestMetamodel::Address.new
|
198
|
+
same_as_jones_work_address.type = 'work'
|
199
|
+
|
200
|
+
assert_equal true,DeepComparator.eql?(same_as_jones_work_address,@jones_work_address)
|
201
|
+
assert_equal true,DeepComparator.eql?(@jones_work_address,same_as_jones_work_address)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_deep_comparator_based_on_ordered_attributes_negative_case
|
205
|
+
assert_equal false,DeepComparator.eql?(@jones_work_address,@jones_home_address)
|
206
|
+
assert_equal false,DeepComparator.eql?(@jones_home_address,@jones_work_address)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_shallow_comparator_based_on_ordered_attributes_negative_case
|
210
|
+
assert_equal false,ShallowComparator.eql?(@jones_home_address,@jones_work_address)
|
211
|
+
assert_equal false,ShallowComparator.eql?(@jones_work_address,@jones_home_address)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_shallow_comparator_based_on_ordered_attributes_positive_case
|
215
|
+
same_as_jones_work_address = OrderedTestMetamodel::Address.new
|
216
|
+
same_as_jones_work_address.type = 'work'
|
217
|
+
|
218
|
+
assert_equal true,ShallowComparator.eql?(same_as_jones_work_address,@jones_work_address)
|
219
|
+
assert_equal true,ShallowComparator.eql?(@jones_work_address,same_as_jones_work_address)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_shallow_comparator_based_on_ordered_attributes_and_children
|
223
|
+
same_as_jones_work_address = OrderedTestMetamodel::Address.new
|
224
|
+
same_as_jones_work_address.type = 'work'
|
225
|
+
|
226
|
+
same_as_jones_home_address = OrderedTestMetamodel::Address.new
|
227
|
+
same_as_jones_home_address.type = 'home'
|
228
|
+
|
229
|
+
similar_to_jones_book_entry = OrderedTestMetamodel::AddressBookEntry.new
|
230
|
+
similar_to_jones_book_entry.name = 'Mr. Jones'
|
231
|
+
|
232
|
+
assert_equal true,ShallowComparator.eql?(@jones_book_entry,similar_to_jones_book_entry)
|
233
|
+
|
234
|
+
similar_to_jones_book_entry.addAddresses(same_as_jones_work_address)
|
235
|
+
similar_to_jones_book_entry.addAddresses(same_as_jones_home_address)
|
236
|
+
|
237
|
+
assert_equal true,ShallowComparator.eql?(@jones_home_address,same_as_jones_home_address)
|
238
|
+
assert_equal true,ShallowComparator.eql?(@jones_work_address,same_as_jones_work_address)
|
239
|
+
assert_equal true,ShallowComparator.eql?(@jones_book_entry,similar_to_jones_book_entry)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_deep_comparator_based_on_ordered_attributes_and_children
|
243
|
+
same_as_jones_work_address = OrderedTestMetamodel::Address.new
|
244
|
+
same_as_jones_work_address.type = 'work'
|
245
|
+
|
246
|
+
same_as_jones_home_address = OrderedTestMetamodel::Address.new
|
247
|
+
same_as_jones_home_address.type = 'home'
|
248
|
+
|
249
|
+
similar_to_jones_book_entry = OrderedTestMetamodel::AddressBookEntry.new
|
250
|
+
similar_to_jones_book_entry.name = 'Mr. Jones'
|
251
|
+
|
252
|
+
assert_equal false,DeepComparator.eql?(@jones_book_entry,similar_to_jones_book_entry)
|
253
|
+
|
254
|
+
similar_to_jones_book_entry.addAddresses(same_as_jones_work_address)
|
255
|
+
similar_to_jones_book_entry.addAddresses(same_as_jones_home_address)
|
256
|
+
|
257
|
+
assert_equal true,DeepComparator.eql?(@jones_home_address,same_as_jones_home_address)
|
258
|
+
assert_equal true,DeepComparator.eql?(@jones_work_address,same_as_jones_work_address)
|
259
|
+
assert_equal true,DeepComparator.eql?(@jones_book_entry,similar_to_jones_book_entry)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_comparison_with_null_reference_shallow_comparator
|
263
|
+
assert_equal true, ShallowComparator.eql?(@ferrari_enzo,@auto_without_engine)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_comparison_with_null_reference_deep_comparator
|
267
|
+
assert_equal false, DeepComparator.eql?(@ferrari_enzo,@auto_without_engine)
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_comparison_only_child_equal_deep_comparator
|
271
|
+
assert_equal true, DeepComparator.eql?(@ferrari_enzo,@ferrari_superenzo)
|
272
|
+
assert_equal false, DeepComparator.eql?(@ferrari_enzo,@ferrari_superextraenzo)
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class NavigationExtensionsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
module TestMetamodel
|
6
|
+
|
7
|
+
class Address < RGen::MetamodelBuilder::MMBase
|
8
|
+
include RGen::Ext::NavigationExtensions
|
9
|
+
has_attr 'type', String
|
10
|
+
has_attr 'street', String
|
11
|
+
has_attr 'number', String
|
12
|
+
end
|
13
|
+
|
14
|
+
class AddressBookEntry < RGen::MetamodelBuilder::MMBase
|
15
|
+
include RGen::Ext::NavigationExtensions
|
16
|
+
has_attr 'name', String
|
17
|
+
contains_many_uni 'addresses', Address
|
18
|
+
end
|
19
|
+
|
20
|
+
class AddressBook < RGen::MetamodelBuilder::MMBase
|
21
|
+
include RGen::Ext::NavigationExtensions
|
22
|
+
contains_many_uni 'entries', AddressBookEntry
|
23
|
+
end
|
24
|
+
|
25
|
+
class Engine < RGen::MetamodelBuilder::MMBase
|
26
|
+
has_attr 'code',String
|
27
|
+
has_attr 'horse_power',Integer
|
28
|
+
end
|
29
|
+
|
30
|
+
class Car < RGen::MetamodelBuilder::MMBase
|
31
|
+
include RGen::Ext::NavigationExtensions
|
32
|
+
contains_one_uni 'engine', Engine
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
@jones_work_address = TestMetamodel::Address.new
|
39
|
+
@jones_work_address.type = 'work'
|
40
|
+
|
41
|
+
@jones_home_address = TestMetamodel::Address.new
|
42
|
+
@jones_home_address.type = 'home'
|
43
|
+
|
44
|
+
@jones_book_entry = TestMetamodel::AddressBookEntry.new
|
45
|
+
@jones_book_entry.name = 'Mr. Jones'
|
46
|
+
@jones_book_entry.addAddresses(@jones_work_address)
|
47
|
+
@jones_book_entry.addAddresses(@jones_home_address)
|
48
|
+
|
49
|
+
@smith_shop_address = TestMetamodel::Address.new
|
50
|
+
@smith_shop_address.type = 'shop'
|
51
|
+
|
52
|
+
@smith_home_address = TestMetamodel::Address.new
|
53
|
+
@smith_home_address.type = 'home'
|
54
|
+
|
55
|
+
@smith_book_entry = TestMetamodel::AddressBookEntry.new
|
56
|
+
@smith_book_entry.name = 'Mr. Smith'
|
57
|
+
@smith_book_entry.addAddresses(@smith_shop_address)
|
58
|
+
@smith_book_entry.addAddresses(@smith_home_address)
|
59
|
+
|
60
|
+
@green_book_entry = TestMetamodel::AddressBookEntry.new
|
61
|
+
@green_book_entry.name = 'Mr. Green'
|
62
|
+
|
63
|
+
@address_book_1 = TestMetamodel::AddressBook.new
|
64
|
+
@address_book_1.addEntries(@jones_book_entry)
|
65
|
+
@address_book_1.addEntries(@smith_book_entry)
|
66
|
+
@address_book_1.addEntries(@green_book_entry)
|
67
|
+
|
68
|
+
@ferrari_v8 = TestMetamodel::Engine.new({:horse_power => 800, :code => 'Ferrari-V8'})
|
69
|
+
@ferrari_enzo = TestMetamodel::Car.new
|
70
|
+
@ferrari_enzo.engine = @ferrari_v8
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_root_is_self_object_for_dangling_object
|
74
|
+
a = TestMetamodel::Address.new
|
75
|
+
assert a==a.root
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_root_is_direct_container
|
79
|
+
a1 = TestMetamodel::Address.new
|
80
|
+
a1.type = 'work'
|
81
|
+
a2 = TestMetamodel::Address.new
|
82
|
+
a2.type = 'home'
|
83
|
+
abe = TestMetamodel::AddressBookEntry.new
|
84
|
+
abe.addAddresses(a1)
|
85
|
+
abe.addAddresses(a2)
|
86
|
+
assert abe==a1.root
|
87
|
+
assert abe==a2.root
|
88
|
+
assert abe==abe.root
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_root_is_top_container
|
92
|
+
a1 = TestMetamodel::Address.new
|
93
|
+
a1.type = 'work'
|
94
|
+
a2 = TestMetamodel::Address.new
|
95
|
+
a2.type = 'home'
|
96
|
+
abe = TestMetamodel::AddressBookEntry.new
|
97
|
+
abe.name = 'Mr. Jones'
|
98
|
+
abe.addAddresses(a1)
|
99
|
+
abe.addAddresses(a2)
|
100
|
+
ab = TestMetamodel::AddressBook.new
|
101
|
+
ab.addEntries(abe)
|
102
|
+
assert ab==a1.root
|
103
|
+
assert ab==a2.root
|
104
|
+
assert ab==abe.root
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_all_children_empty
|
108
|
+
# this node has not containment relations
|
109
|
+
assert_equal [],@jones_work_address.all_children
|
110
|
+
# this node has containment relations
|
111
|
+
assert_equal [],@green_book_entry.all_children
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_all_children_not_empty
|
115
|
+
assert_equal(
|
116
|
+
[@jones_book_entry,@smith_book_entry,@green_book_entry],
|
117
|
+
@address_book_1.all_children)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_all_children_single_containement
|
121
|
+
assert_equal([@ferrari_v8], @ferrari_enzo.all_children)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_all_children_deep_not_empty
|
125
|
+
assert_equal 7,@address_book_1.all_children_deep.count
|
126
|
+
# direct children
|
127
|
+
assert @address_book_1.all_children_deep.include?(
|
128
|
+
@jones_book_entry)
|
129
|
+
assert @address_book_1.all_children_deep.include?(
|
130
|
+
@smith_book_entry)
|
131
|
+
assert @address_book_1.all_children_deep.include?(
|
132
|
+
@green_book_entry)
|
133
|
+
# non-direct children
|
134
|
+
assert @address_book_1.all_children_deep.include?(
|
135
|
+
@jones_work_address)
|
136
|
+
assert @address_book_1.all_children_deep.include?(
|
137
|
+
@jones_home_address)
|
138
|
+
assert @address_book_1.all_children_deep.include?(
|
139
|
+
@smith_shop_address)
|
140
|
+
assert @address_book_1.all_children_deep.include?(
|
141
|
+
@smith_home_address)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TraverseTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class C < RGen::MetamodelBuilder::MMBase
|
6
|
+
include RGen::Ext::NavigationExtensions
|
7
|
+
has_attr 'id',Integer
|
8
|
+
end
|
9
|
+
|
10
|
+
class D < RGen::MetamodelBuilder::MMBase
|
11
|
+
include RGen::Ext::NavigationExtensions
|
12
|
+
has_attr 'id',Integer
|
13
|
+
contains_one_uni 'c', C
|
14
|
+
end
|
15
|
+
|
16
|
+
class B < RGen::MetamodelBuilder::MMBase
|
17
|
+
include RGen::Ext::NavigationExtensions
|
18
|
+
has_attr 'id',Integer
|
19
|
+
contains_many_uni 'ds', D
|
20
|
+
end
|
21
|
+
|
22
|
+
class A < RGen::MetamodelBuilder::MMBase
|
23
|
+
include RGen::Ext::NavigationExtensions
|
24
|
+
has_attr 'id',Integer
|
25
|
+
contains_many_uni 'bs', B
|
26
|
+
contains_one_uni 'c', C
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup
|
30
|
+
@d_1 = D.new({:id => 1 })
|
31
|
+
@d_2 = D.new({:id => 2 })
|
32
|
+
@d_3 = D.new({:id => 3 })
|
33
|
+
@c_4 = C.new({:id => 4 })
|
34
|
+
@c_5 = C.new({:id => 5 })
|
35
|
+
@c_6 = C.new({:id => 6 })
|
36
|
+
@b_7 = B.new({:id => 7 })
|
37
|
+
@b_8 = B.new({:id => 8 })
|
38
|
+
@b_9 = B.new({:id => 9 })
|
39
|
+
@a_10 = A.new({:id => 10 })
|
40
|
+
|
41
|
+
@d_1.c = @c_5
|
42
|
+
|
43
|
+
@b_8.addDs @d_2
|
44
|
+
@b_8.addDs @d_3
|
45
|
+
@b_9.addDs @d_1
|
46
|
+
|
47
|
+
@a_10.addBs @b_9
|
48
|
+
@a_10.addBs @b_8
|
49
|
+
@a_10.c = @c_6
|
50
|
+
end
|
51
|
+
|
52
|
+
def assert_ids(expected,actual)
|
53
|
+
assert_equal expected.count,actual.count
|
54
|
+
expected.each do |e|
|
55
|
+
assert actual.find {|a| a.id==e}, "Element with id #{e} not found"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_traverse
|
60
|
+
l = []
|
61
|
+
@a_10.traverse {|n| l<<n if n }
|
62
|
+
assert_ids [10,6,8,9,2,3,1,5], l
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rgen_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Federico Tomassetti
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rgen
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :runtime
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '1.3'
|
37
|
+
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.3'
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
none: false
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
none: false
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
none: false
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
none: false
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
description: Extensions of general use to RGen
|
79
|
+
email:
|
80
|
+
- f.tomassetti@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/rgen/ext.rb
|
92
|
+
- lib/rgen/ext/comparison.rb
|
93
|
+
- lib/rgen/ext/navigation_extensions.rb
|
94
|
+
- lib/rgen/ext/version.rb
|
95
|
+
- rgen_ext.gemspec
|
96
|
+
- test/helper.rb
|
97
|
+
- test/test_comparison.rb
|
98
|
+
- test/test_navigation_extensions.rb
|
99
|
+
- test/test_traverse.rb
|
100
|
+
homepage: http://github.com/ftomassetti/rgen_ext
|
101
|
+
licenses:
|
102
|
+
- Apache License v2
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: '0'
|
114
|
+
hash: 2
|
115
|
+
none: false
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: '0'
|
123
|
+
hash: 2
|
124
|
+
none: false
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Extensions of general use to RGen
|
131
|
+
test_files:
|
132
|
+
- test/helper.rb
|
133
|
+
- test/test_comparison.rb
|
134
|
+
- test/test_navigation_extensions.rb
|
135
|
+
- test/test_traverse.rb
|