surrounded 0.9.10 → 0.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2236ff5ee05ddc4b3c857e3700ca2205fa966e62
4
- data.tar.gz: 7e47950aaac3dd0dc4b74f18409ef5590226b5ef
3
+ metadata.gz: 3364c250a02c0589ae2cbaf9645235cfd83f7406
4
+ data.tar.gz: 28bcbe612f92d77a9df5d4a5294ebc22420013a2
5
5
  SHA512:
6
- metadata.gz: 1b6e97b48a2c4cda950b2507bff57bcb36bad18171774474405d01030f546e43b2df6adb4e8809477517953ee330df5ffde71c8d0e19af1f469103db5eece897
7
- data.tar.gz: 606cb9ba7d77942a770956eb73581bd4f0fe08caf31bd8305ad404dcea7dd2dbe558521fc908160ba91c2b70bf36c644fc4aef65d940efb6353cf502be24ae3b
6
+ metadata.gz: bf99487271fdcc488dbf5b8dc36d8f7fdd66354bb218bf753682de69cc281d63c9808e3c5f3b7a23c7e71a31f61fa8df0643d9ca4b049c47d35e5734c3f63e79
7
+ data.tar.gz: 5ce4fcdc96205adf8e24d31de75e88ce5e42877266c4714a8066084f61d3e598140bf2830f8f7193c63e318d61c9fb627278e3f5e43b7785d954544e895128dd
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.9.11]
6
+
7
+ - Rely on the standard library Forwardable to setup how the RoleMap forwards messages to the container.
8
+ - Update RoleMap role_player? method to rescue from StandardError, a non-implementation-specific exception.
9
+ - Move to using triad 0.3.0 which relies on concurrent-ruby 0.9+ and moves off of thread_safe 0.3.5
10
+
5
11
  ## [0.9.10]
6
12
 
7
13
  - Do something with name collisions when a role player has an existing method of another role in the context.
@@ -5,9 +5,7 @@ module Surrounded
5
5
  module AccessControl
6
6
  def self.extended(base)
7
7
  base.send(:include, AccessMethods)
8
- unless defined?(base::AccessError)
9
- base.const_set(:AccessError, Class.new(::Surrounded::Context::AccessError))
10
- end
8
+ Surrounded::Exceptions.define(base, exceptions: :AccessError)
11
9
  end
12
10
 
13
11
  private
@@ -1,4 +1,5 @@
1
1
  require 'set'
2
+ require 'surrounded/exceptions'
2
3
  require 'surrounded/context/role_map'
3
4
  require 'surrounded/context/role_builders'
4
5
  require 'surrounded/context/initializing'
@@ -31,21 +32,10 @@ module Surrounded
31
32
  extend TriggerControls
32
33
 
33
34
  }
34
- define_exceptions(base)
35
35
  end
36
36
 
37
37
  private
38
38
 
39
- def self.define_exceptions(klass)
40
- self.constants.select{|const|
41
- self.const_get(const) < ::StandardError
42
- }.map{|exception|
43
- unless klass.const_defined?(exception)
44
- klass.const_set(exception, Class.new(self.const_get(exception)))
45
- end
46
- }
47
- end
48
-
49
39
  # Set the default type of implementation for role methods for all contexts.
50
40
  def self.default_role_type
51
41
  @default_role_type ||= :module
@@ -29,7 +29,7 @@ module Surrounded
29
29
 
30
30
  def default_initializer(params, setup_args, &block)
31
31
  private_attr_reader(*setup_args)
32
- @initializer_block = block || nil
32
+ @initializer_block = block
33
33
  mod = Module.new
34
34
  line = __LINE__; mod.class_eval %{
35
35
  def initialize(#{params})
@@ -7,9 +7,7 @@ module Surrounded
7
7
 
8
8
  def self.extended(base)
9
9
  base.send :include, NameCollisionHandler
10
- unless defined?(base::NameCollisionError)
11
- base.const_set(:NameCollinionError, Class.new(::Surrounded::Context::NameCollisionError))
12
- end
10
+ Surrounded::Exceptions.define(base, exceptions: :NameCollisionError)
13
11
  end
14
12
 
15
13
  def on_name_collision(method_name)
@@ -61,7 +59,7 @@ module Surrounded
61
59
  elsif self.class.respond_to?(handler, true)
62
60
  self.class.method(handler)
63
61
  else
64
- method(:nothing)
62
+ raise ArgumentError, %{your name collision handler was set to `#{handler}' but there is no instance nor class method of that name}
65
63
  end
66
64
  end
67
65
  end
@@ -12,6 +12,10 @@ module Surrounded
12
12
 
13
13
  module RoleBuilders
14
14
 
15
+ def self.extended(base)
16
+ Surrounded::Exceptions.define(base, exceptions: :InvalidRoleType)
17
+ end
18
+
15
19
  # Define behaviors for your role players
16
20
  def role(name, type=default_role_type, &block)
17
21
  if type == :module
@@ -1,28 +1,26 @@
1
1
  require 'triad'
2
- require 'surrounded/context_errors'
2
+ require 'forwardable'
3
3
  module Surrounded
4
4
  module Context
5
- class InvalidRole < ::Triad::ItemNotPresent; end
6
-
7
5
  class RoleMap
6
+ extend Forwardable
8
7
 
9
8
  class << self
10
9
  def from_base(klass=::Triad)
11
- role_mapper = Class.new(::Surrounded::Context::RoleMap)
12
- num = __LINE__; role_mapper.class_eval %{
13
- def container
14
- @container ||= #{klass}.new
15
- end
16
- }, __FILE__, num
17
- %w{ update each values keys }.each do |meth|
18
- num = __LINE__; role_mapper.class_eval %{
19
- def #{meth}(*args, &block)
20
- container.send(:#{meth}, *args, &block)
21
- end
22
- }, __FILE__, num
23
- end
10
+ role_mapper = Class.new(self)
11
+ Surrounded::Exceptions.define(role_mapper, exceptions: :ItemNotPresent, namespace: klass)
12
+ role_mapper.container_class=(klass)
13
+ role_mapper.def_delegators :container, :update, :each, :values, :keys
24
14
  role_mapper
25
15
  end
16
+
17
+ def container_class=(klass)
18
+ @container_class = klass
19
+ end
20
+ end
21
+
22
+ def container
23
+ @container ||= self.class.instance_variable_get(:@container_class).new
26
24
  end
27
25
 
28
26
  def role?(role)
@@ -31,7 +29,7 @@ module Surrounded
31
29
 
32
30
  def role_player?(object)
33
31
  !values(object).empty?
34
- rescue ::Triad::ItemNotPresent
32
+ rescue ::StandardError
35
33
  false
36
34
  end
37
35
 
@@ -0,0 +1,11 @@
1
+ module Surrounded
2
+ module Exceptions
3
+ def self.define(klass, exceptions:, namespace: Surrounded::Context)
4
+ Array(exceptions).each{ |exception|
5
+ unless klass.const_defined?(exception)
6
+ klass.const_set(exception, Class.new(namespace.const_get(exception)))
7
+ end
8
+ }
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Surrounded
2
- VERSION = "0.9.10"
2
+ VERSION = "0.9.11"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -5,7 +5,7 @@ require 'surrounded/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "surrounded"
8
- spec.version = Surrounded::VERSION
8
+ spec.version = Surrounded.version
9
9
  spec.authors = ["'Jim Gay'"]
10
10
  spec.email = ["jim@saturnflyer.com"]
11
11
  spec.description = %q{Gives an object implicit access to other objects in it's environment.}
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "triad", "~> 0.2.2"
21
+ spec.add_dependency "triad", "~> 0.3.0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.12"
24
24
  spec.add_development_dependency "rake"
@@ -126,6 +126,21 @@ describe 'handling name collisions' do
126
126
  }
127
127
  end
128
128
 
129
+ it 'can ignore collisions' do
130
+ set_handler :nothing
131
+ assert_output(nil, nil) {
132
+ new_context_with_collision
133
+ }
134
+ end
135
+
136
+ it 'raises an error with an unknown handler' do
137
+ set_handler :barf
138
+ err = assert_raises(ArgumentError) {
139
+ new_context_with_collision
140
+ }
141
+ expect(err.message).must_match(/your name collision handler was set to \`barf' but there is no instance nor class method of that name/)
142
+ end
143
+
129
144
  let(:create_context_with_multiple_collisions){
130
145
  ContextWithMultipleCollisions.new(first: First.new, second: Second.new, third: Third.new)
131
146
  }
@@ -143,7 +158,7 @@ ERR
143
158
 
144
159
  it 'can use a class method' do
145
160
  class ContextOverridesName
146
- def class_method_handler(message)
161
+ def self.class_method_handler(message)
147
162
  puts message
148
163
  end
149
164
  end
@@ -97,6 +97,21 @@ describe Surrounded::Context, '#role?' do
97
97
  end
98
98
  end
99
99
 
100
+ describe Surrounded::Context, '#role_player?' do
101
+ let(:player){ User.new("Jim") }
102
+ let(:other_player){ User.new("Amy") }
103
+ let(:non_player){ User.new("Guille") }
104
+ let(:context){ TestContext.new(player, other_player) }
105
+
106
+ it 'is true if the given object is a role player' do
107
+ expect(context.role_player?(player)).must_equal true
108
+ end
109
+
110
+ it 'is false if the given oject is not a role player' do
111
+ expect(context.role_player?(non_player)).must_equal false
112
+ end
113
+ end
114
+
100
115
  class RoleAssignmentContext
101
116
  extend Surrounded::Context
102
117
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrounded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Jim Gay'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-13 00:00:00.000000000 Z
11
+ date: 2016-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: triad
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.2
19
+ version: 0.3.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: 0.2.2
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -81,8 +81,8 @@ files:
81
81
  - lib/surrounded/context/role_builders.rb
82
82
  - lib/surrounded/context/role_map.rb
83
83
  - lib/surrounded/context/trigger_controls.rb
84
- - lib/surrounded/context_errors.rb
85
84
  - lib/surrounded/east_oriented.rb
85
+ - lib/surrounded/exceptions.rb
86
86
  - lib/surrounded/shortcuts.rb
87
87
  - lib/surrounded/version.rb
88
88
  - surrounded.gemspec
@@ -149,3 +149,4 @@ test_files:
149
149
  - test/surrounded_context_test.rb
150
150
  - test/surrounded_test.rb
151
151
  - test/test_helper.rb
152
+ has_rdoc:
@@ -1,5 +0,0 @@
1
- require 'triad'
2
- module Surrounded
3
- module Context
4
- end
5
- end