reality-facets 1.3.0 → 1.4.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: bb281ab73c6286e5c1a45396e041b0fc1d93970a
4
- data.tar.gz: 64a10ebd482f32587978b40bdc4965534e07c028
3
+ metadata.gz: a0dfc8b7b3827dc8fb701309931179fa1ac10702
4
+ data.tar.gz: 3a3a1f3306010ba1bdc930b4bb437621960a7465
5
5
  SHA512:
6
- metadata.gz: 0550cce27e866f4489e052caf535ccff1a07ebc7a492599403e0d462bffb115c3737ff81b28c5489090e72520893b4f163d4f56d33a2bcc3f540de42babdd2bc
7
- data.tar.gz: c1a021e2d8ba9783fc0dbe6f5f6349e889bbad06caa639971796adac11e082800ba01b12abafc425faa28d52b6f4fd4351021b23bb0cb85935d5874966ba1f60
6
+ metadata.gz: 9620619a6997219813fa821d7f76bfb494b2b394cb497fdc3d74a0787ad4f8f283c73a6181d2e44192729338d2d3b4ba186948c6e2c24457e3a3c3b928af0904
7
+ data.tar.gz: c32dad7876933dc4dc84d643ea0a4a1900733273f0460523b48f2206e01c90c51df30d03149aef70d1a298cc223f04eaf8f9123552b9369550303e07ac4f6193
@@ -57,9 +57,30 @@ module Reality #nodoc
57
57
 
58
58
  extension_name = "#{::Reality::Naming.pascal_case(self.key)}#{model_class.name.gsub(/^.*\:\:([^\:]+)/, '\1')}Facet"
59
59
  definitions = target_manager.container.facet_definitions
60
- definitions.class_eval("class #{extension_name} < Reality.base_element(:container_key => :#{target.inverse_access_method}); end")
60
+ definitions.class_eval(<<-RUBY)
61
+ class #{extension_name} < Reality.base_element(:container_key => :#{target.inverse_access_method})
62
+ def facet_key
63
+ :#{self.key}
64
+ end
65
+
66
+ def self.facet_key
67
+ :#{self.key}
68
+ end
69
+
70
+ def target_key
71
+ :#{target.key}
72
+ end
73
+
74
+ def self.target_key
75
+ :#{target.key}
76
+ end
77
+
78
+ def parent
79
+ self.#{target.inverse_access_method}
80
+ end
81
+ end
82
+ RUBY
61
83
  extension_instance = definitions.const_get(extension_name)
62
- extension_instance.class_eval("def parent; self.#{target.inverse_access_method}; end")
63
84
  extension_instance.class_eval(&block) if block_given?
64
85
 
65
86
  model_extension = target.extension_module
@@ -69,7 +90,7 @@ module Reality #nodoc
69
90
  end
70
91
 
71
92
  def facet_#{self.key}
72
- raise "Attempted to access '#{self.key}' facet for model '#{model_class.name}' when facet disabled." unless #{self.key}?
93
+ Reality::Facets.error("Attempted to access '#{self.key}' facet for model '#{model_class.name}' when facet disabled.") unless #{self.key}?
73
94
  @facet_#{self.key} ||= #{extension_instance.name}.new(self)
74
95
  end
75
96
  RUBY
@@ -77,4 +98,3 @@ module Reality #nodoc
77
98
  end
78
99
  end
79
100
  end
80
-
@@ -27,7 +27,7 @@ module Reality #nodoc
27
27
  @extension_module = nil
28
28
 
29
29
  if @container_key && !target_manager.target_by_key?(@container_key)
30
- raise "Target '#{key}' defines container as '#{@container_key}' but no such target exists."
30
+ Reality::Facets.error("Target '#{key}' defines container as '#{@container_key}' but no such target exists.")
31
31
  end
32
32
 
33
33
  @target_manager.send(:register_target, self)
@@ -54,8 +54,8 @@ module Reality #nodoc
54
54
  end
55
55
 
56
56
  def apply_extension_to(object)
57
- raise "Can not apply extension to model object of type #{object.class} as it is not of expected model type #{model_class.name} for target #{key}" unless object.is_a?(model_class)
58
- raise "Attempted to apply extension multiple time to model object of type #{model_class.name} for target #{key}" if object.instance_variable_defined?('@facet_extension_active')
57
+ Reality::Facets.error("Can not apply extension to model object of type #{object.class} as it is not of expected model type #{model_class.name} for target #{key}") unless object.is_a?(model_class)
58
+ Reality::Facets.error("Attempted to apply extension multiple time to model object of type #{model_class.name} for target #{key}") if object.instance_variable_defined?('@facet_extension_active')
59
59
  object.class.send(:include, extension_module)
60
60
  object.instance_variable_set('@facet_container', target_manager.container)
61
61
  object.instance_variable_set('@facet_extension_active', true)
@@ -95,7 +95,7 @@ module Reality #nodoc
95
95
 
96
96
  def target_by_key(key)
97
97
  target = target_map[key.to_sym]
98
- raise "Can not find target with key '#{key}'" unless target
98
+ Reality::Facets.error("Can not find target with key '#{key}'") unless target
99
99
  target
100
100
  end
101
101
 
@@ -103,7 +103,7 @@ module Reality #nodoc
103
103
  target_map.each do |key, target|
104
104
  return target if target.model_class == model_class
105
105
  end
106
- raise "Can not find target with model class '#{model_class.name}'"
106
+ Reality::Facets.error("Can not find target with model class '#{model_class.name}'")
107
107
  end
108
108
 
109
109
  def apply_extension(model)
@@ -130,8 +130,8 @@ module Reality #nodoc
130
130
  private
131
131
 
132
132
  def register_target(target)
133
- raise "Attempting to define target #{target.key} when targets have been locked." if (@targets_locked ||= false)
134
- raise "Attempting to redefine target #{target.key}" if target_map[target.key]
133
+ Reality::Facets.error("Attempting to define target #{target.key} when targets have been locked.") if (@targets_locked ||= false)
134
+ Reality::Facets.error("Attempting to redefine target #{target.key}") if target_map[target.key]
135
135
  target_map[target.key] = target
136
136
  end
137
137
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-facets}
5
- s.version = '1.3.0'
5
+ s.version = '1.4.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.has_rdoc = false
22
22
  s.rdoc_options = %w(--line-numbers --inline-source --title reality-facets)
23
23
 
24
- s.add_dependency 'reality-core', '>= 1.4.0'
25
- s.add_dependency 'reality-naming', '>= 1.4.0'
24
+ s.add_dependency 'reality-core', '>= 1.6.0'
25
+ s.add_dependency 'reality-naming', '>= 1.6.0'
26
26
  s.add_dependency 'reality-orderedhash', '>= 1.0.0'
27
27
 
28
28
  s.add_development_dependency(%q<minitest>, ['= 5.9.1'])
@@ -63,6 +63,10 @@ class Reality::Facets::TestFacet < Reality::TestCase
63
63
  assert_equal true, project.respond_to?(:imit)
64
64
  assert_equal true, project.respond_to?(:facet_imit)
65
65
  assert_equal 'GwtMyProject', project.imit.name
66
+ assert_equal :imit, project.imit.facet_key
67
+ assert_equal :project, project.imit.target_key
68
+ assert_equal :imit, project.imit.class.facet_key
69
+ assert_equal :project, project.imit.class.target_key
66
70
 
67
71
  # These methods all test that FacetModule has been mixed in.
68
72
  assert_equal 'GwtMyProject', project.facet(:imit).name
@@ -71,6 +75,11 @@ class Reality::Facets::TestFacet < Reality::TestCase
71
75
  assert_equal [:gwt, :gwt_rpc, :imit], project.enabled_facets
72
76
  assert_equal [:gwt, :gwt_rpc, :imit], component.enabled_facets
73
77
 
78
+ assert_equal :imit, component.imit.facet_key
79
+ assert_equal :component, component.imit.target_key
80
+ assert_equal :imit, component.imit.class.facet_key
81
+ assert_equal :component, component.imit.class.target_key
82
+
74
83
  # Ensure there is a link back to the container using inverse_access_method
75
84
  assert_equal project, project.imit.project
76
85
  assert_equal project, project.imit.parent
@@ -16,8 +16,8 @@ class Reality::Facets::TestFacetContainer < Reality::TestCase
16
16
  assert_equal [], TestFacetContainer.facet_keys
17
17
  assert_equal 0, TestFacetContainer.facets.size
18
18
 
19
- assert_raise_message("Unknown facet 'gwt'") { TestFacetContainer.facet_by_name(:gwt) }
20
- assert_raise_message("Unknown facet 'gwt_rpc'") { TestFacetContainer.facet_by_name(:gwt_rpc) }
19
+ assert_facet_error("Unknown facet 'gwt'") { TestFacetContainer.facet_by_name(:gwt) }
20
+ assert_facet_error("Unknown facet 'gwt_rpc'") { TestFacetContainer.facet_by_name(:gwt_rpc) }
21
21
 
22
22
  # Make sure we can add targets
23
23
  TestFacetContainer.target_manager.target(Component, :component)
@@ -25,7 +25,7 @@ class Reality::Facets::TestFacetContainer < Reality::TestCase
25
25
  TestFacetContainer.facet(:gwt)
26
26
 
27
27
  # targets should be locked after first facet defined
28
- assert_raise_message('Attempting to define target component when targets have been locked.') do
28
+ assert_facet_error('Attempting to define target component when targets have been locked.') do
29
29
  TestFacetContainer.target_manager.target(Component, :component)
30
30
  end
31
31
 
@@ -36,7 +36,7 @@ class Reality::Facets::TestFacetContainer < Reality::TestCase
36
36
  assert_equal %w(gwt), TestFacetContainer.facet_keys
37
37
  assert_equal 1, TestFacetContainer.facets.size
38
38
 
39
- assert_raise_message("Unknown facet 'gwt_rpc'") { TestFacetContainer.facet_by_name(:gwt_rpc) }
39
+ assert_facet_error("Unknown facet 'gwt_rpc'") { TestFacetContainer.facet_by_name(:gwt_rpc) }
40
40
 
41
41
  assert_equal TestFacetContainer, TestFacetContainer.facet_by_name(:gwt).facet_container
42
42
  assert_equal :gwt, TestFacetContainer.facet_by_name(:gwt).key
@@ -57,9 +57,9 @@ class Reality::Facets::TestFacetContainer < Reality::TestCase
57
57
  assert_equal [:gwt], TestFacetContainer.facet_by_name(:gwt_rpc).required_facets
58
58
  assert_equal [], TestFacetContainer.facet_by_name(:gwt_rpc).suggested_facets
59
59
 
60
- assert_raise_message('Attempting to redefine facet gwt') { TestFacetContainer.facet(:gwt) }
60
+ assert_facet_error('Attempting to redefine facet gwt') { TestFacetContainer.facet(:gwt) }
61
61
 
62
- assert_raise_message("Unknown definition form '{:x=>:y, :z=>1}'") { TestFacetContainer.facet(:x => :y, :z => 1) }
62
+ assert_facet_error("Unknown definition form '{:x=>:y, :z=>1}'") { TestFacetContainer.facet(:x => :y, :z => 1) }
63
63
  end
64
64
 
65
65
  def test_dependent_facets
@@ -87,7 +87,7 @@ class Reality::Facets::TestFacetedModel < Reality::TestCase
87
87
  assert_equal [], attribute2.enabled_facets
88
88
 
89
89
  repository.enable_facet(:imit)
90
- assert_raise_message('Facet imit already enabled.') { repository.enable_facet(:imit) }
90
+ assert_facet_error('Facet imit already enabled.') { repository.enable_facet(:imit) }
91
91
 
92
92
  assert_equal [:json, :gwt, :gwt_rpc, :jpa, :imit], repository.enabled_facets
93
93
  assert_equal [:gwt, :gwt_rpc, :jpa, :imit], entity1.enabled_facets
@@ -136,7 +136,7 @@ class Reality::Facets::TestFacetedModel < Reality::TestCase
136
136
  assert_equal [:jpa, :json], attribute1.enabled_facets
137
137
  assert_equal [:jpa, :json], attribute2.enabled_facets
138
138
 
139
- assert_raise_message('Facet json already enabled.') { repository.enable_facets!([:json]) }
139
+ assert_facet_error('Facet json already enabled.') { repository.enable_facets!([:json]) }
140
140
 
141
141
  # Try using brackets
142
142
  repository.disable_facets([:json, :imit])
@@ -85,9 +85,9 @@ class Reality::Facets::TestTargetManager < Reality::TestCase
85
85
  assert_equal :prj, target1.inverse_access_method
86
86
  assert_equal 'Reality::TestCase::TestFacetContainer::FacetDefinitions::ProjectExtension', target1.extension_module.name
87
87
 
88
- assert_raise_message('Attempting to redefine target project') { Reality::Facets::Target.new(target_manager, Project, :project, nil, {}) }
88
+ assert_facet_error('Attempting to redefine target project') { Reality::Facets::Target.new(target_manager, Project, :project, nil, {}) }
89
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, {}) }
90
+ assert_facet_error("Target 'foo' defines container as 'bar' but no such target exists.") { Reality::Facets::Target.new(target_manager, Unused, :foo, :bar, {}) }
91
91
  end
92
92
 
93
93
  def test_target_manager_basic_operation
@@ -98,7 +98,7 @@ class Reality::Facets::TestTargetManager < Reality::TestCase
98
98
  assert_equal [], target_manager.target_keys
99
99
  assert_equal false, target_manager.target_by_key?(:project)
100
100
 
101
- assert_raise_message("Can not find target with model class 'Reality::Facets::TestTargetManager::Project'") { target_manager.target_by_model_class(Project) }
101
+ assert_facet_error("Can not find target with model class 'Reality::Facets::TestTargetManager::Project'") { target_manager.target_by_model_class(Project) }
102
102
 
103
103
  target_manager.target(Project, :project)
104
104
 
@@ -123,7 +123,7 @@ class Reality::Facets::TestTargetManager < Reality::TestCase
123
123
  assert_equal 1, target_manager.targets_by_container(:project).size
124
124
  assert_equal :component, target_manager.targets_by_container(:project)[0].key
125
125
 
126
- assert_raise_message("Can not find target with key 'foo'") { target_manager.target_by_key(:foo) }
126
+ assert_facet_error("Can not find target with key 'foo'") { target_manager.target_by_key(:foo) }
127
127
  end
128
128
 
129
129
  def test_apply_extension
data/test/helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'reality/facets'
6
6
 
7
7
  class Reality::TestCase < Minitest::Test
8
8
  include Test::Unit::Assertions
9
+ include Reality::Logging::Assertions
9
10
 
10
11
  module TestFacetContainer
11
12
  extend Reality::Facets::FacetContainer
@@ -24,4 +25,10 @@ class Reality::TestCase < Minitest::Test
24
25
  def setup
25
26
  TestFacetContainer.reset
26
27
  end
28
+
29
+ def assert_facet_error(expected_message, &block)
30
+ assert_logging_error(Reality::Facets, expected_message) do
31
+ yield block
32
+ end
33
+ end
27
34
  end
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.3.0
4
+ version: 1.4.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-14 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.0
19
+ version: 1.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.0
26
+ version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: reality-naming
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.0
33
+ version: 1.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.0
40
+ version: 1.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: reality-orderedhash
43
43
  requirement: !ruby/object:Gem::Requirement