reality-model 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +6 -0
- data/.gitignore +8 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/CONTRIBUTING.md +26 -0
- data/Gemfile +5 -0
- data/LICENSE +201 -0
- data/README.md +9 -0
- data/Rakefile +18 -0
- data/lib/reality/model/core.rb +19 -0
- data/lib/reality/model/model_element.rb +202 -0
- data/lib/reality/model/repository.rb +131 -0
- data/lib/reality/model.rb +22 -0
- data/reality-model.gemspec +31 -0
- data/test/helper.rb +25 -0
- data/test/test_model_element.rb +512 -0
- data/test/test_repository.rb +225 -0
- metadata +147 -0
@@ -0,0 +1,225 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class Reality::Model::TestRepository < Reality::Model::TestCase
|
4
|
+
def test_basic_operation
|
5
|
+
repository = Reality::Model::Repository.new(:MyTypeSystem, MyContainer)
|
6
|
+
|
7
|
+
assert_equal repository.key, :MyTypeSystem
|
8
|
+
assert_equal repository.model_container, MyContainer
|
9
|
+
assert_equal repository.instance_container, MyContainer
|
10
|
+
assert_equal repository.log_container, MyContainer
|
11
|
+
assert_equal repository.facet_container, nil
|
12
|
+
assert_equal repository.faceted?, false
|
13
|
+
assert_equal repository.model_element_keys, []
|
14
|
+
assert_equal repository.model_elements, []
|
15
|
+
assert_equal repository.model_elements_by_container(:entity), []
|
16
|
+
|
17
|
+
assert_equal repository.model_element_by_key?(:entity), false
|
18
|
+
|
19
|
+
assert_model_error("Can not find model element 'entity' in repository 'MyTypeSystem'.") do
|
20
|
+
repository.model_element_by_key(:entity)
|
21
|
+
end
|
22
|
+
|
23
|
+
element = repository.model_element(:entity)
|
24
|
+
|
25
|
+
assert_equal repository.model_element_by_key?(:entity), true
|
26
|
+
assert_equal repository.model_element_keys, ['entity']
|
27
|
+
assert_equal repository.model_elements, [element]
|
28
|
+
assert_equal repository.model_elements_by_container(:entity), []
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_validate_options
|
32
|
+
assert_model_error("Unknown option ':x' passed to create repository") do
|
33
|
+
Reality::Model::Repository.new(:MyTypeSystem, MyContainer, :x => 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_model_error('Unknown options [:x, :z] passed to create repository') do
|
37
|
+
Reality::Model::Repository.new(:MyTypeSystem, MyContainer, :x => 1, :z => 1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module MyLogContainer
|
42
|
+
end
|
43
|
+
|
44
|
+
module MyFacetContainer
|
45
|
+
end
|
46
|
+
|
47
|
+
module MyInstanceContainer
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_create_no_defaults
|
51
|
+
repository = Reality::Model::Repository.new(:MyTypeSystem,
|
52
|
+
MyContainer,
|
53
|
+
:instance_container => MyInstanceContainer,
|
54
|
+
:log_container => MyLogContainer,
|
55
|
+
:facet_container => MyFacetContainer)
|
56
|
+
|
57
|
+
assert_equal repository.key, :MyTypeSystem
|
58
|
+
assert_equal repository.model_container, MyContainer
|
59
|
+
assert_equal repository.instance_container, MyInstanceContainer
|
60
|
+
assert_equal repository.log_container, MyLogContainer
|
61
|
+
assert_equal repository.facet_container, MyFacetContainer
|
62
|
+
assert_equal repository.faceted?, true
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_yield
|
66
|
+
repository = Reality::Model::Repository.new(:MyTypeSystem, MyContainer) do |repo|
|
67
|
+
repo.model_element(:entity)
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_equal repository.locked?, true
|
71
|
+
|
72
|
+
assert_equal repository.key, :MyTypeSystem
|
73
|
+
assert_equal repository.model_element_by_key?(:entity), true
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_register_duplicates
|
77
|
+
repository = Reality::Model::Repository.new(:MyTypeSystem, MyContainer)
|
78
|
+
|
79
|
+
repository.model_element(:entity)
|
80
|
+
|
81
|
+
assert_equal repository.model_element_by_key?(:entity), true
|
82
|
+
|
83
|
+
assert_model_error("Attempting to redefine model element 'MyTypeSystem.entity'") do
|
84
|
+
repository.model_element(:entity)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_model_elements_by_container
|
89
|
+
repository = Reality::Model::Repository.new(:MyTypeSystem, MyContainer)
|
90
|
+
|
91
|
+
repository.model_element(:entity)
|
92
|
+
|
93
|
+
assert_equal repository.model_elements_by_container(:entity), []
|
94
|
+
|
95
|
+
element2 = repository.model_element(:attribute, :entity)
|
96
|
+
element3 = repository.model_element(:view, :entity)
|
97
|
+
|
98
|
+
assert_equal repository.model_elements_by_container(:entity), [element2, element3]
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_lock
|
102
|
+
repository = Reality::Model::Repository.new(:Domgen, MyContainer)
|
103
|
+
|
104
|
+
assert_equal repository.locked?, false
|
105
|
+
|
106
|
+
repository.model_element(:entity)
|
107
|
+
repository.model_element(:attribute, :entity)
|
108
|
+
|
109
|
+
assert_equal repository.model_elements.size, 2
|
110
|
+
|
111
|
+
assert_equal false, MyContainer.const_defined?(:Entity)
|
112
|
+
assert_equal false, MyContainer.const_defined?(:Attribute)
|
113
|
+
|
114
|
+
repository.lock!
|
115
|
+
|
116
|
+
assert_equal true, MyContainer.const_defined?(:Entity)
|
117
|
+
assert_equal true, MyContainer.const_defined?(:Attribute)
|
118
|
+
|
119
|
+
assert_equal repository.locked?, true
|
120
|
+
|
121
|
+
assert_model_error("Attempting to define model element 'Domgen.view' when repository is locked.") do
|
122
|
+
repository.model_element(:view, :entity)
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_model_error("Attempting to lock repository 'Domgen' when repository is already locked.") do
|
126
|
+
repository.lock!
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_define_ruby_classes
|
131
|
+
repository = Reality::Model::Repository.new(:Resgen, MyContainer)
|
132
|
+
Reality::Model::ModelElement.new(repository, :project, nil, {})
|
133
|
+
Reality::Model::ModelElement.new(repository, :bundle, :project, {})
|
134
|
+
|
135
|
+
assert_equal false, MyContainer.const_defined?(:Project)
|
136
|
+
assert_equal false, MyContainer.const_defined?(:Bundle)
|
137
|
+
|
138
|
+
repository.send(:define_ruby_classes)
|
139
|
+
|
140
|
+
assert_equal true, MyContainer.const_defined?(:Project)
|
141
|
+
assert_equal true, MyContainer.const_defined?(:Bundle)
|
142
|
+
end
|
143
|
+
|
144
|
+
module MyInstanceContainer2
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_lock_called_if_block_supplied_to_constructor
|
148
|
+
assert_equal false, MyContainer.const_defined?(:Project)
|
149
|
+
assert_equal false, MyContainer.const_defined?(:Bundle)
|
150
|
+
|
151
|
+
repository = Reality::Model::Repository.new(:Resgen, MyContainer, :instance_container => MyInstanceContainer2) do |r|
|
152
|
+
r.model_element(:project)
|
153
|
+
r.model_element(:bundle, :project)
|
154
|
+
end
|
155
|
+
|
156
|
+
assert_equal true, repository.locked?
|
157
|
+
|
158
|
+
assert_equal true, MyContainer.const_defined?(:Project)
|
159
|
+
assert_equal true, MyContainer.const_defined?(:Bundle)
|
160
|
+
|
161
|
+
assert_true MyInstanceContainer2.public_methods.include?(:projects)
|
162
|
+
assert_true MyInstanceContainer2.public_methods.include?(:project_by_name)
|
163
|
+
assert_true MyInstanceContainer2.public_methods.include?(:project_by_name?)
|
164
|
+
assert_true MyInstanceContainer2.public_methods.include?(:project)
|
165
|
+
end
|
166
|
+
|
167
|
+
module MyInstanceContainer3
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_define_top_level_instance_accessors
|
171
|
+
|
172
|
+
assert_false MyInstanceContainer3.public_methods.include?(:projects)
|
173
|
+
assert_false MyInstanceContainer3.public_methods.include?(:project_by_name)
|
174
|
+
assert_false MyInstanceContainer3.public_methods.include?(:project_by_name?)
|
175
|
+
assert_false MyInstanceContainer3.public_methods.include?(:project)
|
176
|
+
|
177
|
+
repository = Reality::Model::Repository.new(:Resgen, MyContainer, :instance_container => MyInstanceContainer3)
|
178
|
+
Reality::Model::ModelElement.new(repository, :project, nil, {})
|
179
|
+
|
180
|
+
repository.send(:define_top_level_instance_accessors)
|
181
|
+
|
182
|
+
assert_true MyInstanceContainer3.public_methods.include?(:projects)
|
183
|
+
assert_true MyInstanceContainer3.public_methods.include?(:project_by_name)
|
184
|
+
assert_true MyInstanceContainer3.public_methods.include?(:project_by_name?)
|
185
|
+
assert_true MyInstanceContainer3.public_methods.include?(:project)
|
186
|
+
end
|
187
|
+
|
188
|
+
module MyFacetManager
|
189
|
+
extend Reality::Facets::FacetContainer
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_define_facet_targets
|
193
|
+
assert_equal MyFacetManager.target_manager.target_keys, []
|
194
|
+
|
195
|
+
Reality::Model::Repository.new(:Resgen, MyContainer, :facet_container => MyFacetManager) do |r|
|
196
|
+
r.model_element(:project)
|
197
|
+
r.model_element(:bundle, :project, :inverse_access_method => :bnd, :access_method => :bnds)
|
198
|
+
r.model_element(:image, :bundle)
|
199
|
+
end
|
200
|
+
|
201
|
+
assert_equal MyFacetManager.target_manager.target_keys, [:project, :bundle, :image]
|
202
|
+
|
203
|
+
target1 = MyFacetManager.target_manager.target_by_key(:project)
|
204
|
+
target2 = MyFacetManager.target_manager.target_by_key(:bundle)
|
205
|
+
target3 = MyFacetManager.target_manager.target_by_key(:image)
|
206
|
+
|
207
|
+
assert_equal :project, target1.inverse_access_method
|
208
|
+
assert_equal :projects, target1.access_method
|
209
|
+
assert_equal nil, target1.container_key
|
210
|
+
assert_equal :project, target1.key
|
211
|
+
assert_equal Reality::Model::TestCase::MyContainer::Project, target1.model_class
|
212
|
+
|
213
|
+
assert_equal :bnd, target2.inverse_access_method
|
214
|
+
assert_equal :bnds, target2.access_method
|
215
|
+
assert_equal :project, target2.container_key
|
216
|
+
assert_equal :bundle, target2.key
|
217
|
+
assert_equal Reality::Model::TestCase::MyContainer::Bundle, target2.model_class
|
218
|
+
|
219
|
+
assert_equal :image, target3.inverse_access_method
|
220
|
+
assert_equal :images, target3.access_method
|
221
|
+
assert_equal :bundle, target3.container_key
|
222
|
+
assert_equal :image, target3.key
|
223
|
+
assert_equal Reality::Model::TestCase::MyContainer::Image, target3.model_class
|
224
|
+
end
|
225
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reality-model
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Donald
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: reality-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: reality-naming
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: reality-orderedhash
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: reality-facets
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.9.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.9.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.1.5
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.1.5
|
97
|
+
description: Utility classes for defining a domain model.
|
98
|
+
email: peter@realityforge.org
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- ".gitattributes"
|
104
|
+
- ".gitignore"
|
105
|
+
- ".ruby-version"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CONTRIBUTING.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/reality/model.rb
|
113
|
+
- lib/reality/model/core.rb
|
114
|
+
- lib/reality/model/model_element.rb
|
115
|
+
- lib/reality/model/repository.rb
|
116
|
+
- reality-model.gemspec
|
117
|
+
- test/helper.rb
|
118
|
+
- test/test_model_element.rb
|
119
|
+
- test/test_repository.rb
|
120
|
+
homepage: https://github.com/realityforge/reality-model
|
121
|
+
licenses: []
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options:
|
125
|
+
- "--line-numbers"
|
126
|
+
- "--inline-source"
|
127
|
+
- "--title"
|
128
|
+
- reality-model
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.5.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Utility classes for defining a domain model.
|
147
|
+
test_files: []
|