drsi 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +2 -2
- data/lib/drsi/rolable.rb +14 -12
- data/lib/drsi/version.rb +1 -1
- data/spec/roleplayers_spec.rb +3 -4
- 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: 6b99bdc02a78b72391449fe80e587f114dc2fca0
|
4
|
+
data.tar.gz: 707d75c55602ea782f5fdda5441c475f263de7bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a994734ded3c5039e348dc4fcd2daa40f2927b8a48606daf6bc8fa01d3c8dc2113030fb05faa82279a2391ec8f23df287d061afeb76e2bfa90f48e2fc6f43b5
|
7
|
+
data.tar.gz: 3831df641d260d23c583a1d79d93870cc81c8ef82c336b94703187bfe7693717da83376506e277ca4b889c943ac5eb26cf8c15cfb87b3d4cd812700ae2468bc1
|
data/README.md
CHANGED
@@ -69,9 +69,9 @@ Inside a context instance, every player object incorporates the behaviour (metho
|
|
69
69
|
The Account instances above are players. They are accesible inside #run through #source_account and #target_account private methods.
|
70
70
|
Also, every role player has private access to the rest of role players in the context.
|
71
71
|
|
72
|
-
Unlike the Presenter approach in dci-ruby (where the object to play a role and the one inside the context playing it are associated but different), this
|
72
|
+
Unlike the Presenter approach in dci-ruby (where the object to play a role and the one inside the context playing it are associated but different), this injection approach preserves unique identity of objects playing roles.
|
73
73
|
|
74
|
-
When
|
74
|
+
When instantiating a Context, the extra no-role pairs given as arguments are read-only attributes accessible via #settings:
|
75
75
|
|
76
76
|
MoneyTransfer[:source_account => Account.new(1),
|
77
77
|
:target_account => Account.new(2),
|
data/lib/drsi/rolable.rb
CHANGED
@@ -8,11 +8,18 @@ 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 the role defined as a module in '
|
12
|
-
|
11
|
+
# Make an object play (in the given 'context') the role defined as a module in 'role_mod':
|
12
|
+
# - Get or extend a new empty role module,
|
13
|
+
# - Copy role_mod instance_methods into it,
|
14
|
+
# - Inject context and settings methods.
|
15
|
+
def __play_role!(role_mod, a_context)
|
13
16
|
new_role = __next_empty_role
|
14
|
-
new_role.__copy_instance_methods_from(
|
15
|
-
new_role.
|
17
|
+
new_role.__copy_instance_methods_from(role_mod)
|
18
|
+
new_role.class_exec(a_context) do |the_context|
|
19
|
+
private
|
20
|
+
define_method(:context) {the_context}
|
21
|
+
define_method(:settings) {|*keys| context.send(:settings, *keys)}
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
# Make an object stop playing the last role it plays, if any.
|
@@ -55,12 +62,7 @@ module Rolable
|
|
55
62
|
end
|
56
63
|
|
57
64
|
# The context a role is played within. This method must be overidden in every __role definition module.
|
58
|
-
def context
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
# The role definition code also have private access to the extra args given in the context instantiation.
|
63
|
-
def settings(*keys)
|
64
|
-
context.send(:settings, *keys) if context
|
65
|
-
end
|
65
|
+
# def context
|
66
|
+
# nil
|
67
|
+
# end
|
66
68
|
end
|
data/lib/drsi/version.rb
CHANGED
data/spec/roleplayers_spec.rb
CHANGED
@@ -38,7 +38,7 @@ describe 'RolePlayers' do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def check_role1_context_access
|
41
|
-
role1.context == self
|
41
|
+
[!role1.respond_to?(:context), role1.private_methods.map(&:to_s).include?('context'), role1.send(:context) == self].uniq == [true]
|
42
42
|
end
|
43
43
|
|
44
44
|
def check_role1_settings_access
|
@@ -95,9 +95,8 @@ describe 'RolePlayers' do
|
|
95
95
|
@player1.name.should eq('player1')
|
96
96
|
@player2.should_not respond_to(:role1)
|
97
97
|
@player2.should_not respond_to(:context)
|
98
|
-
@
|
99
|
-
@
|
100
|
-
@player1.send(:settings).should be_nil
|
98
|
+
@player2.should_not respond_to(:settings)
|
99
|
+
(@player2.private_methods.map(&:to_s) & ['role1', 'context', 'settings']).should be_empty
|
101
100
|
end
|
102
101
|
|
103
102
|
|
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.0.
|
4
|
+
version: 0.0.2
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|