drsi 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/drsi/dci/context.rb +2 -2
- data/lib/drsi/dci/role.rb +1 -1
- data/lib/drsi/module.rb +2 -5
- data/lib/drsi/rolable.rb +14 -14
- data/lib/drsi/version.rb +1 -1
- data/spec/multiplayers_spec.rb +5 -4
- data/spec/roleplayers_spec.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfba058e060a1aeff1bbd634bf58b5c75d2c6f96
|
4
|
+
data.tar.gz: be2b11f836e7e14ebdfedce0445132c154bb6ef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adbad678c9cf9ae41f91cee89d62a34f4b5fa4783cd7faa161eb1c5afd8727a7c74917202c46f58b35f9409f23d96111465bc3f7169c3a3a7c6c04f4c943d8ef
|
7
|
+
data.tar.gz: 3fb6063db4e72a8163e83c04209148d965a80b71ca9484f4a0d01c243dc8d2d0678b9a337eca096f7b822c56a8c994959a9bfd0bd18101a6964688105dc6d2d3
|
data/lib/drsi/dci/context.rb
CHANGED
@@ -146,8 +146,8 @@ module DCI
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def player_already_playing_role_in_this_context?(player, rolekey)
|
149
|
-
context = player.send(:
|
150
|
-
return false unless player.send(:
|
149
|
+
context = player.send(:__context)
|
150
|
+
return false unless player.send(:__rolekey) == rolekey
|
151
151
|
context == self or context.class == self.class
|
152
152
|
end
|
153
153
|
|
data/lib/drsi/dci/role.rb
CHANGED
@@ -10,7 +10,7 @@ module DCI
|
|
10
10
|
# Defines a new private reader instance method for a context mate role, delegating it to the context object.
|
11
11
|
def add_role_reader_for!(rolekey)
|
12
12
|
return if private_method_defined?(rolekey)
|
13
|
-
define_method(rolekey) {
|
13
|
+
define_method(rolekey) {__context.send(rolekey)}
|
14
14
|
private rolekey
|
15
15
|
end
|
16
16
|
|
data/lib/drsi/module.rb
CHANGED
@@ -7,6 +7,7 @@ class Module
|
|
7
7
|
type = methods_type.to_s.split('_').first.to_sym
|
8
8
|
__add_instance_methods(methods, type)
|
9
9
|
end
|
10
|
+
self
|
10
11
|
end
|
11
12
|
|
12
13
|
|
@@ -16,11 +17,7 @@ class Module
|
|
16
17
|
# Also, set their visibility from 'type' (:public, :protected, :private).
|
17
18
|
def __add_instance_methods(methods, type)
|
18
19
|
module_exec(methods, type) do |methods, type|
|
19
|
-
methods.each
|
20
|
-
define_method(method.name) do |*args, &block|
|
21
|
-
method.bind(self).call(*args, &block)
|
22
|
-
end
|
23
|
-
end
|
20
|
+
methods.each {|method| define_method(method.name, method)}
|
24
21
|
send(type, *methods.map(&:name))
|
25
22
|
end
|
26
23
|
end
|
data/lib/drsi/rolable.rb
CHANGED
@@ -8,18 +8,17 @@ require 'drsi/module'
|
|
8
8
|
# reusing the empty ones or adding and extending new ones when it is needed.
|
9
9
|
module Rolable
|
10
10
|
|
11
|
-
# Make an object play (in the given '
|
11
|
+
# Make an object play (in the given 'a_context') the role defined as a module in 'role_mod':
|
12
12
|
# - Get or extend a new empty role module,
|
13
13
|
# - Copy role_mod instance_methods into it,
|
14
|
-
# - Inject
|
14
|
+
# - Inject __context and settings methods.
|
15
15
|
def __play_role!(a_rolekey, role_mod, a_context)
|
16
|
-
new_role =
|
17
|
-
new_role.__copy_instance_methods_from(role_mod)
|
16
|
+
new_role = __next_role_for(role_mod)
|
18
17
|
new_role.class_exec(a_context, a_rolekey) do |the_context, the_rolekey|
|
19
18
|
private
|
20
|
-
define_method(:
|
21
|
-
define_method(:
|
22
|
-
define_method(:settings) {|*keys|
|
19
|
+
define_method(:__rolekey) {the_rolekey}
|
20
|
+
define_method(:__context) {the_context}
|
21
|
+
define_method(:settings) {|*keys| __context.send(:settings, *keys)}
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
@@ -49,26 +48,27 @@ module Rolable
|
|
49
48
|
|
50
49
|
# Returns the highest role module free of methods. If none, creates a new empty module ready to be filled with
|
51
50
|
# role instance methods.
|
52
|
-
def
|
51
|
+
def __next_role_for(mod)
|
53
52
|
@__last_role_index = __last_role_index + 1
|
54
|
-
|
55
|
-
|
53
|
+
new_role = __last_role
|
54
|
+
new_role ? new_role.__copy_instance_methods_from(mod) : __add_role_for(mod)
|
56
55
|
end
|
57
56
|
|
58
57
|
# Creates and extends a new module ready to be filled with role instance methods.
|
59
|
-
def
|
60
|
-
role =
|
58
|
+
def __add_role_for(mod)
|
59
|
+
role = mod.dup
|
61
60
|
extend(role)
|
62
61
|
__roles << role
|
62
|
+
role
|
63
63
|
end
|
64
64
|
|
65
65
|
# The context within this object is playing its last role. This method must be overidden in every __role definition module.
|
66
|
-
def
|
66
|
+
def __context
|
67
67
|
nil
|
68
68
|
end
|
69
69
|
|
70
70
|
# The rolekey this object is playing its last role. This method must be overidden in every __role definition module.
|
71
|
-
def
|
71
|
+
def __rolekey
|
72
72
|
nil
|
73
73
|
end
|
74
74
|
end
|
data/lib/drsi/version.rb
CHANGED
data/spec/multiplayers_spec.rb
CHANGED
@@ -54,7 +54,8 @@ describe 'Role MultiPlayers' do
|
|
54
54
|
|
55
55
|
def roles2_have_context_private_access?
|
56
56
|
role2[0..-1].all? do |roleplayer|
|
57
|
-
[!roleplayer.respond_to?(:
|
57
|
+
[!roleplayer.respond_to?(:__context), roleplayer.private_methods.map(&:to_s).include?('__context'), roleplayer.send(:__context) == self,
|
58
|
+
!roleplayer.respond_to?(:__rolekey), roleplayer.private_methods.map(&:to_s).include?('__rolekey'), roleplayer.send(:__rolekey) == :role2].uniq == [true]
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
@@ -97,7 +98,7 @@ describe 'Role MultiPlayers' do
|
|
97
98
|
@testing_roleplayers_context.roles2_external_interfaces_accessible?(@player2.name, @player22.name).should be_true
|
98
99
|
end
|
99
100
|
|
100
|
-
it("They have private access to the context.") do
|
101
|
+
it("They have private access to the context via #__context.") do
|
101
102
|
@testing_roleplayers_context.roles2_have_context_private_access?.should be_true
|
102
103
|
end
|
103
104
|
|
@@ -114,8 +115,8 @@ describe 'Role MultiPlayers' do
|
|
114
115
|
@player22.name.should eq('player22')
|
115
116
|
expect{@player2.send(:role1)}.to raise_error
|
116
117
|
expect{@player22.send(:role1)}.to raise_error
|
117
|
-
@player2.send(:
|
118
|
-
@player22.send(:
|
118
|
+
@player2.send(:__context).should be_nil
|
119
|
+
@player22.send(:__context).should be_nil
|
119
120
|
expect{@player2.send(:settings)}.to raise_error
|
120
121
|
expect{@player22.send(:settings)}.to raise_error
|
121
122
|
end
|
data/spec/roleplayers_spec.rb
CHANGED
@@ -39,7 +39,8 @@ describe 'RolePlayers' do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def check_role1_private_context_access
|
42
|
-
[!role1.respond_to?(:
|
42
|
+
[!role1.respond_to?(:__context), role1.private_methods.map(&:to_s).include?('__context'), role1.send(:__context) == self,
|
43
|
+
!role1.respond_to?(:__rolekey), role1.private_methods.map(&:to_s).include?('__rolekey'), role1.send(:__rolekey) == :role1].uniq == [true]
|
43
44
|
end
|
44
45
|
|
45
46
|
def check_role1_settings_access
|
@@ -95,7 +96,7 @@ describe 'RolePlayers' do
|
|
95
96
|
@player1.should_not respond_to(:role1method1)
|
96
97
|
@player2.private_methods.map(&:to_s).should_not include(:private_role2method2)
|
97
98
|
@player1.name.should eq('player1')
|
98
|
-
@player2.send(:
|
99
|
+
@player2.send(:__context).should be_nil
|
99
100
|
expect {@player2.send(:settings)}.to raise_error
|
100
101
|
expect {@player2.send(:role1)}.to raise_error
|
101
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drsi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorenzo Tello
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|