reality-facets 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d17f63aa3fd221512dc2cf8fb3305c70a33f18df
4
- data.tar.gz: 0e66691871d7376d787d10eed9bf6d84f28ed982
3
+ metadata.gz: eb2cf5b835141d1956e52495b6e86298c7a0bd38
4
+ data.tar.gz: f63d857ce9b317ae26a8272a6c31d31d8eed00cd
5
5
  SHA512:
6
- metadata.gz: b39725276dde3d9d2cd95068d597525f5e9c92e9836087f8af4bdae090d642f230c8699c99b957278cc6dd4fcfc34a9088a97fd1bc9cbf6e5f8b9693aa79b3ba
7
- data.tar.gz: f06caabcc236eb7899f1eac6aa95fd11535689d14eefc4a6dd337996b7dfdab85365ea0ab4c0b40b69243f4ee6e21bf9505ed8ff4301a65dfda70e64859f126f
6
+ metadata.gz: 19ce8a8033d1b9f83aad57e287ec49d53f2ebffb502820ec6be488949a961cc950b1b626b04b58a9af30e739553ea625eb9268696dfbc6d69ea6db5f75b53aed
7
+ data.tar.gz: 3162fe711a8e2b827657dd3e3bf2ce093ecece7c97724abbe532ba5b1eefe47bc3fca62422c7722215e449e61a2ecfb824c349e1e691062bcc36058eba8e1ffb
@@ -20,6 +20,7 @@ require 'reality/orderedhash'
20
20
 
21
21
  require 'reality/facets/core'
22
22
  require 'reality/facets/target_manager'
23
+ require 'reality/facets/extension_manager'
23
24
  require 'reality/facets/faceted_model'
24
25
  require 'reality/facets/facet'
25
26
  require 'reality/facets/facet_container'
@@ -0,0 +1,62 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ module Reality #nodoc
16
+ module Facets #nodoc
17
+ class ExtensionManager
18
+ def initialize
19
+ @locked = false
20
+ end
21
+
22
+ # An array of modules that should be mixed in to every extension object
23
+ def instance_extensions
24
+ instance_extension_list.dup
25
+ end
26
+
27
+ # Add a ruby module that will be applied to all extension objects
28
+ def instance_extension(extension)
29
+ Facets.error("Attempting to define instance extension #{extension} after extension manager is locked") if locked?
30
+ instance_extension_list << extension
31
+ end
32
+
33
+ # An array of modules that should be mixed in to the singleton class of extension objects
34
+ def singleton_extensions
35
+ singleton_extension_list.dup
36
+ end
37
+
38
+ def singleton_extension(extension)
39
+ Facets.error("Attempting to define singleton extension #{extension} after extension manager is locked") if locked?
40
+ singleton_extension_list << extension
41
+ end
42
+
43
+ def lock!
44
+ @locked = true
45
+ end
46
+
47
+ def locked?
48
+ !!(@locked ||= nil)
49
+ end
50
+
51
+ private
52
+
53
+ def singleton_extension_list
54
+ @singleton_extensions ||= []
55
+ end
56
+
57
+ def instance_extension_list
58
+ @instance_extensions ||= []
59
+ end
60
+ end
61
+ end
62
+ end
@@ -57,6 +57,7 @@ module Reality #nodoc
57
57
  end
58
58
 
59
59
  def enhance(model_class, &block)
60
+ facet_container.extension_manager.lock!
60
61
  target_manager = facet_container.target_manager
61
62
  target = target_manager.target_by_model_class(model_class)
62
63
 
@@ -88,6 +89,14 @@ end
88
89
  RUBY
89
90
  @model_extension_instances[model_class] = definitions.const_get(extension_name)
90
91
 
92
+ facet_container.extension_manager.instance_extensions.each do |extension|
93
+ @model_extension_instances[model_class].class_eval { include extension }
94
+ end
95
+
96
+ facet_container.extension_manager.singleton_extensions.each do |extension|
97
+ @model_extension_instances[model_class].singleton_class.class_eval { include extension }
98
+ end
99
+
91
100
  target.extension_module.class_eval <<-RUBY
92
101
  def #{self.key}
93
102
  self.facet_#{self.key}
@@ -19,18 +19,6 @@ module Reality #nodoc
19
19
  base.class_eval 'module FacetDefinitions; end'
20
20
  end
21
21
 
22
- # An array of modules that should be mixed in to every extension object
23
- def facet_extensions
24
- facet_extension_list.dup
25
- end
26
-
27
- # Add a ruby module that will be applied to all extension objects
28
- def facet_extension(extension)
29
- Facets.error("Attempting to define facet extension #{extension} after facet manager is locked") if locked?
30
- facet_extension_list << extension
31
- target_manager.lock!
32
- end
33
-
34
22
  def facet?(name)
35
23
  facet_by_name?(name)
36
24
  end
@@ -62,13 +50,16 @@ module Reality #nodoc
62
50
 
63
51
  def lock!
64
52
  @locked = true
65
- apply_facet_extensions
66
53
  end
67
54
 
68
55
  def locked?
69
56
  !!(@locked ||= nil)
70
57
  end
71
58
 
59
+ def extension_manager
60
+ @extension_manager ||= Reality::Facets::ExtensionManager.new
61
+ end
62
+
72
63
  def target_manager
73
64
  @target_manager ||= Reality::Facets::TargetManager.new(self)
74
65
  end
@@ -166,24 +157,6 @@ module Reality #nodoc
166
157
  true
167
158
  end
168
159
 
169
- def apply_facet_extensions
170
- facet_extension_list.each do |extension|
171
- facet_map.values.each do |facet|
172
- target_manager.targets.each do |target|
173
- if facet.enhanced?(target.model_class)
174
- facet.enhance(target.model_class) do
175
- include extension
176
- end
177
- end
178
- end
179
- end
180
- end
181
- end
182
-
183
- def facet_extension_list
184
- @facet_extensions ||= []
185
- end
186
-
187
160
  def register_facet(facet)
188
161
  target_manager.lock!
189
162
  Facets.error("Attempting to define facet #{facet.key} after facet manager is locked") if locked?
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-facets}
5
- s.version = '1.6.0'
5
+ s.version = '1.7.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+
3
+ class Reality::Facets::TestExtensionManager < Reality::TestCase
4
+
5
+ module MyExtensionModule
6
+ end
7
+
8
+ module MySingletonExtensionModule
9
+ end
10
+
11
+ def test_basic_operation
12
+
13
+ extension_manager = Reality::Facets::ExtensionManager.new
14
+ assert_equal false, extension_manager.locked?
15
+
16
+ assert_equal [], extension_manager.instance_extensions
17
+ extension_manager.instance_extension(MyExtensionModule)
18
+ assert_equal [MyExtensionModule], extension_manager.instance_extensions
19
+
20
+ assert_equal [], extension_manager.singleton_extensions
21
+ extension_manager.singleton_extension(MySingletonExtensionModule)
22
+ assert_equal [MySingletonExtensionModule], extension_manager.singleton_extensions
23
+
24
+ extension_manager.lock!
25
+
26
+ assert_facet_error('Attempting to define instance extension Reality::Facets::TestExtensionManager::MyExtensionModule after extension manager is locked') do
27
+ extension_manager.instance_extension(MyExtensionModule)
28
+ end
29
+
30
+ assert_facet_error('Attempting to define singleton extension Reality::Facets::TestExtensionManager::MySingletonExtensionModule after extension manager is locked') do
31
+ extension_manager.singleton_extension(MySingletonExtensionModule)
32
+ end
33
+ end
34
+ end
@@ -115,8 +115,13 @@ class Reality::Facets::TestFacet < Reality::TestCase
115
115
  end
116
116
  end
117
117
 
118
- def test_common_extension_modules
118
+ module MySingletonExtensionModule
119
+ def blah
120
+ 'X'
121
+ end
122
+ end
119
123
 
124
+ def test_common_extension_modules
120
125
  assert_equal false, TestFacetContainer.facet_by_name?(:gwt)
121
126
 
122
127
  TestFacetContainer.target_manager.target(Project2, :project)
@@ -125,9 +130,13 @@ class Reality::Facets::TestFacet < Reality::TestCase
125
130
  :project)
126
131
 
127
132
 
128
- assert_equal [], TestFacetContainer.facet_extensions
129
- TestFacetContainer.facet_extension(MyExtensionModule)
130
- assert_equal [MyExtensionModule], TestFacetContainer.facet_extensions
133
+ assert_equal [], TestFacetContainer.extension_manager.instance_extensions
134
+ TestFacetContainer.extension_manager.instance_extension(MyExtensionModule)
135
+ assert_equal [MyExtensionModule], TestFacetContainer.extension_manager.instance_extensions
136
+
137
+ assert_equal [], TestFacetContainer.extension_manager.singleton_extensions
138
+ TestFacetContainer.extension_manager.singleton_extension(MySingletonExtensionModule)
139
+ assert_equal [MySingletonExtensionModule], TestFacetContainer.extension_manager.singleton_extensions
131
140
 
132
141
  Reality::Facets::Facet.new(TestFacetContainer, :gwt) do |f|
133
142
  f.enhance(Project2) do
@@ -146,6 +155,7 @@ class Reality::Facets::TestFacet < Reality::TestCase
146
155
  assert_equal true, project.gwt?
147
156
  assert_equal 'GwtMyProject', project.gwt.name
148
157
  assert_equal 'yo', project.gwt.hello_message
158
+ assert_equal 'X', project.gwt.class.blah
149
159
  assert_equal false, component.respond_to?(:gwt)
150
160
  end
151
161
  end
@@ -39,10 +39,6 @@ class Reality::Facets::TestFacetContainer < Reality::TestCase
39
39
  assert_equal %w(gwt), TestFacetContainer.facet_keys
40
40
  assert_equal 1, TestFacetContainer.facets.size
41
41
 
42
- assert_equal [], TestFacetContainer.facet_extensions
43
- TestFacetContainer.facet_extension(MyExtensionModule)
44
- assert_equal [MyExtensionModule], TestFacetContainer.facet_extensions
45
-
46
42
  assert_facet_error("Unknown facet 'gwt_rpc'") { TestFacetContainer.facet_by_name(:gwt_rpc) }
47
43
 
48
44
  assert_equal TestFacetContainer, TestFacetContainer.facet_by_name(:gwt).facet_container
data/test/helper.rb CHANGED
@@ -4,6 +4,12 @@ require 'minitest/autorun'
4
4
  require 'test/unit/assertions'
5
5
  require 'reality/facets'
6
6
 
7
+ class Reality::Facets::ExtensionManager
8
+ def unlock!
9
+ @locked = false
10
+ end
11
+ end
12
+
7
13
  class Reality::TestCase < Minitest::Test
8
14
  include Test::Unit::Assertions
9
15
  include Reality::Logging::Assertions
@@ -14,8 +20,8 @@ class Reality::TestCase < Minitest::Test
14
20
 
15
21
  def reset
16
22
  @locked = false
23
+ extension_manager.unlock!
17
24
  facet_map.clear
18
- facet_extension_list.clear
19
25
  target_manager.reset_targets
20
26
  TestFacetContainer::FacetDefinitions.constants.each do |constant|
21
27
  TestFacetContainer::FacetDefinitions.send(:remove_const, constant)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reality-facets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Donald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core
@@ -97,12 +97,14 @@ files:
97
97
  - Rakefile
98
98
  - lib/reality/facets.rb
99
99
  - lib/reality/facets/core.rb
100
+ - lib/reality/facets/extension_manager.rb
100
101
  - lib/reality/facets/facet.rb
101
102
  - lib/reality/facets/facet_container.rb
102
103
  - lib/reality/facets/faceted_model.rb
103
104
  - lib/reality/facets/generators_integration.rb
104
105
  - lib/reality/facets/target_manager.rb
105
106
  - reality-facets.gemspec
107
+ - test/facets/test_extension_manager.rb
106
108
  - test/facets/test_facet.rb
107
109
  - test/facets/test_facet_container.rb
108
110
  - test/facets/test_faceted_model.rb