reality-facets 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 +9 -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 +8 -0
- data/Rakefile +18 -0
- data/lib/reality/facets.rb +25 -0
- data/lib/reality/facets/core.rb +19 -0
- data/lib/reality/facets/facet.rb +80 -0
- data/lib/reality/facets/facet_container.rb +143 -0
- data/lib/reality/facets/faceted_model.rb +98 -0
- data/lib/reality/facets/target_manager.rb +143 -0
- data/reality-facets.gemspec +30 -0
- data/test/facets/test_facet.rb +80 -0
- data/test/facets/test_facet_container.rb +64 -0
- data/test/facets/test_faceted_model.rb +267 -0
- data/test/facets/test_target_manager.rb +196 -0
- data/test/helper.rb +27 -0
- metadata +137 -0
@@ -0,0 +1,196 @@
|
|
1
|
+
require File.expand_path('../../helper', __FILE__)
|
2
|
+
|
3
|
+
class Reality::Facets::TestTargetManager < Reality::TestCase
|
4
|
+
|
5
|
+
class Unused < Reality.base_element(:name => true)
|
6
|
+
end
|
7
|
+
|
8
|
+
class DataModule < Reality.base_element(:name => true, :container_key => :repository)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Repository < Reality.base_element(:name => true)
|
12
|
+
def data_module(name, options = {}, &block)
|
13
|
+
data_module_map[name.to_s] = DataModule.new(self, name, options, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def data_modules
|
17
|
+
data_module_map.values
|
18
|
+
end
|
19
|
+
|
20
|
+
def data_module_map
|
21
|
+
@data_module_map ||= {}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Fragment < Reality.base_element(:name => true, :container_key => :component)
|
26
|
+
end
|
27
|
+
|
28
|
+
class Component < Reality.base_element(:name => true, :container_key => :project)
|
29
|
+
def fragment(name, options = {}, &block)
|
30
|
+
fragment_map[name.to_s] = Component.new(self, name, options, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fragments
|
34
|
+
fragment_map.values
|
35
|
+
end
|
36
|
+
|
37
|
+
def fragment_map
|
38
|
+
@fragment_map ||= {}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Project < Reality.base_element(:name => true)
|
43
|
+
def component(name, options = {}, &block)
|
44
|
+
component_map[name.to_s] = Component.new(self, name, options, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def components
|
48
|
+
component_map.values
|
49
|
+
end
|
50
|
+
|
51
|
+
def component_map
|
52
|
+
@component_map ||= {}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_target
|
57
|
+
target_manager = Reality::Facets::TargetManager.new(TestFacetContainer)
|
58
|
+
target1 = Reality::Facets::Target.new(target_manager, Repository, :repository, nil, {})
|
59
|
+
|
60
|
+
assert_equal target_manager, target1.target_manager
|
61
|
+
assert_equal Repository, target1.model_class
|
62
|
+
assert_equal :repository, target1.key
|
63
|
+
assert_equal nil, target1.container_key
|
64
|
+
assert_equal :repositories, target1.access_method
|
65
|
+
assert_equal :repository, target1.inverse_access_method
|
66
|
+
assert_equal 'Reality::TestCase::TestFacetContainer::FacetDefinitions::RepositoryExtension', target1.extension_module.name
|
67
|
+
|
68
|
+
target2 = Reality::Facets::Target.new(target_manager, DataModule, :data_module, :repository, {})
|
69
|
+
|
70
|
+
assert_equal target_manager, target2.target_manager
|
71
|
+
assert_equal DataModule, target2.model_class
|
72
|
+
assert_equal :data_module, target2.key
|
73
|
+
assert_equal :repository, target2.container_key
|
74
|
+
assert_equal :data_modules, target2.access_method
|
75
|
+
assert_equal :data_module, target2.inverse_access_method
|
76
|
+
assert_equal 'Reality::TestCase::TestFacetContainer::FacetDefinitions::DataModuleExtension', target2.extension_module.name
|
77
|
+
|
78
|
+
target1 = Reality::Facets::Target.new(target_manager, Project, :project, nil, :access_method => :project_set, :inverse_access_method => 'prj')
|
79
|
+
|
80
|
+
assert_equal target_manager, target1.target_manager
|
81
|
+
assert_equal Project, target1.model_class
|
82
|
+
assert_equal :project, target1.key
|
83
|
+
assert_equal nil, target1.container_key
|
84
|
+
assert_equal :project_set, target1.access_method
|
85
|
+
assert_equal :prj, target1.inverse_access_method
|
86
|
+
assert_equal 'Reality::TestCase::TestFacetContainer::FacetDefinitions::ProjectExtension', target1.extension_module.name
|
87
|
+
|
88
|
+
assert_raise_message('Attempting to redefine target project') { Reality::Facets::Target.new(target_manager, Project, :project, nil, {}) }
|
89
|
+
|
90
|
+
assert_raise_message("Target 'foo' defines container as 'bar' but no such target exists.") { Reality::Facets::Target.new(target_manager, Unused, :foo, :bar, {}) }
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_target_manager_basic_operation
|
94
|
+
|
95
|
+
target_manager = Reality::Facets::TargetManager.new(TestFacetContainer)
|
96
|
+
|
97
|
+
assert_equal false, target_manager.is_target_valid?(:project)
|
98
|
+
assert_equal [], target_manager.target_keys
|
99
|
+
assert_equal false, target_manager.target_by_key?(:project)
|
100
|
+
|
101
|
+
assert_raise_message("Can not find target with model class 'Reality::Facets::TestTargetManager::Project'") { target_manager.target_by_model_class(Project) }
|
102
|
+
|
103
|
+
target_manager.target(Project, :project)
|
104
|
+
|
105
|
+
assert_equal true, target_manager.is_target_valid?(:project)
|
106
|
+
assert_equal [:project], target_manager.target_keys
|
107
|
+
assert_equal true, target_manager.target_by_key?(:project)
|
108
|
+
assert_equal 1, target_manager.targets.size
|
109
|
+
assert_equal :project, target_manager.targets[0].key
|
110
|
+
# noinspection RubyArgCount
|
111
|
+
assert_equal :project, target_manager.target_by_model_class(Project).key
|
112
|
+
|
113
|
+
target_manager.target(Component, :component, :project, :access_method => :comps)
|
114
|
+
|
115
|
+
assert_equal true, target_manager.is_target_valid?(:component)
|
116
|
+
assert_equal true, target_manager.target_by_key?(:component)
|
117
|
+
assert_equal 2, target_manager.targets.size
|
118
|
+
target = target_manager.target_by_key(:component)
|
119
|
+
assert_equal :component, target.key
|
120
|
+
assert_equal :project, target.container_key
|
121
|
+
assert_equal :comps, target.access_method
|
122
|
+
|
123
|
+
assert_equal 1, target_manager.targets_by_container(:project).size
|
124
|
+
assert_equal :component, target_manager.targets_by_container(:project)[0].key
|
125
|
+
|
126
|
+
assert_raise_message("Can not find target with key 'foo'") { target_manager.target_by_key(:foo) }
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_apply_extension
|
130
|
+
TestFacetContainer.target_manager.target(Project, :project)
|
131
|
+
TestFacetContainer.target_manager.target(Component, :component, :project)
|
132
|
+
TestFacetContainer.target_manager.target(Fragment, :fragment, :component)
|
133
|
+
|
134
|
+
TestFacetContainer.facet(:json)
|
135
|
+
TestFacetContainer.facet(:jpa)
|
136
|
+
TestFacetContainer.facet(:gwt) do |f|
|
137
|
+
f.enhance(Project) do
|
138
|
+
def name
|
139
|
+
"Gwt#{project.name}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
project = Project.new(:MyProject) do |p|
|
145
|
+
p.component(:MyComponent1) do |c|
|
146
|
+
c.fragment(:MyFragment)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
component1 = project.components[0]
|
151
|
+
fragment1 = component1.fragments[0]
|
152
|
+
|
153
|
+
assert_equal false, project.respond_to?(:facet_enabled?)
|
154
|
+
assert_equal false, component1.respond_to?(:facet_enabled?)
|
155
|
+
assert_equal false, fragment1.respond_to?(:facet_enabled?)
|
156
|
+
|
157
|
+
assert_equal false, project.respond_to?(:parent)
|
158
|
+
assert_equal false, component1.respond_to?(:parent)
|
159
|
+
assert_equal false, fragment1.respond_to?(:parent)
|
160
|
+
|
161
|
+
TestFacetContainer.target_manager.apply_extension(project)
|
162
|
+
TestFacetContainer.target_manager.apply_extension(component1)
|
163
|
+
TestFacetContainer.target_manager.apply_extension(fragment1)
|
164
|
+
|
165
|
+
assert_equal true, project.respond_to?(:facet_enabled?)
|
166
|
+
assert_equal true, component1.respond_to?(:facet_enabled?)
|
167
|
+
assert_equal true, fragment1.respond_to?(:facet_enabled?)
|
168
|
+
|
169
|
+
assert_equal false, project.respond_to?(:parent)
|
170
|
+
assert_equal true, component1.respond_to?(:parent)
|
171
|
+
assert_equal true, fragment1.respond_to?(:parent)
|
172
|
+
|
173
|
+
assert_equal project, component1.parent
|
174
|
+
assert_equal component1, fragment1.parent
|
175
|
+
|
176
|
+
project.enable_facets(:json, :gwt)
|
177
|
+
|
178
|
+
assert_equal [:json, :gwt], project.enabled_facets
|
179
|
+
|
180
|
+
assert_equal true, project.respond_to?(:facet_enabled?)
|
181
|
+
assert_equal true, component1.respond_to?(:facet_enabled?)
|
182
|
+
assert_equal true, fragment1.respond_to?(:facet_enabled?)
|
183
|
+
|
184
|
+
assert_equal [:json, :gwt], component1.enabled_facets
|
185
|
+
|
186
|
+
component1.disable_facet(:gwt)
|
187
|
+
|
188
|
+
assert_equal [:json], component1.enabled_facets
|
189
|
+
|
190
|
+
assert_equal true, project.respond_to?(:facet_enabled?)
|
191
|
+
assert_equal true, component1.respond_to?(:facet_enabled?)
|
192
|
+
assert_equal true, fragment1.respond_to?(:facet_enabled?)
|
193
|
+
|
194
|
+
assert_equal [:json], fragment1.enabled_facets
|
195
|
+
end
|
196
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'test/unit/assertions'
|
5
|
+
require 'reality/facets'
|
6
|
+
|
7
|
+
class Reality::TestCase < Minitest::Test
|
8
|
+
include Test::Unit::Assertions
|
9
|
+
|
10
|
+
module TestFacetContainer
|
11
|
+
extend Reality::Facets::FacetContainer
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def reset
|
15
|
+
facet_map.clear
|
16
|
+
target_manager.reset_targets
|
17
|
+
TestFacetContainer::FacetDefinitions.constants.each do |constant|
|
18
|
+
TestFacetContainer::FacetDefinitions.send(:remove_const, constant)
|
19
|
+
end if TestFacetContainer.const_defined?(:FacetDefinitions)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
TestFacetContainer.reset
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reality-facets
|
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-07 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.4.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.4.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.4.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.4.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: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.9.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.9.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-unit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.5
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.5
|
83
|
+
description: A basic toolkit for binding facets or extensions to model objects.
|
84
|
+
email: peter@realityforge.org
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitattributes"
|
90
|
+
- ".gitignore"
|
91
|
+
- ".ruby-version"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CONTRIBUTING.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/reality/facets.rb
|
99
|
+
- lib/reality/facets/core.rb
|
100
|
+
- lib/reality/facets/facet.rb
|
101
|
+
- lib/reality/facets/facet_container.rb
|
102
|
+
- lib/reality/facets/faceted_model.rb
|
103
|
+
- lib/reality/facets/target_manager.rb
|
104
|
+
- reality-facets.gemspec
|
105
|
+
- test/facets/test_facet.rb
|
106
|
+
- test/facets/test_facet_container.rb
|
107
|
+
- test/facets/test_faceted_model.rb
|
108
|
+
- test/facets/test_target_manager.rb
|
109
|
+
- test/helper.rb
|
110
|
+
homepage: https://github.com/realityforge/reality-facets
|
111
|
+
licenses: []
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options:
|
115
|
+
- "--line-numbers"
|
116
|
+
- "--inline-source"
|
117
|
+
- "--title"
|
118
|
+
- reality-facets
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.5.1
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: A basic toolkit for binding facets or extensions to model objects.
|
137
|
+
test_files: []
|