dci-ruby 2.1.1 → 2.1.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.
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/examples/money_transfer.rb +5 -4
- data/lib/dci-ruby/dci/context.rb +2 -15
- data/lib/dci-ruby/dci/role.rb +37 -7
- data/lib/dci-ruby/version.rb +1 -1
- metadata +4 -4
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/examples/money_transfer.rb
CHANGED
@@ -21,7 +21,7 @@ class MoneyTransferContext < DCI::Context
|
|
21
21
|
|
22
22
|
def run_transfer_of(amount)
|
23
23
|
self.balance -= amount
|
24
|
-
puts "\tAccount(\##{account_id}) sent #{amount}€ to Account(\##{target_account.account_id})."
|
24
|
+
puts "\t\tAccount(\##{account_id}) sent #{amount}€ to Account(\##{target_account.account_id})."
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,7 @@ class MoneyTransferContext < DCI::Context
|
|
31
31
|
|
32
32
|
def run_transfer_of(amount)
|
33
33
|
self.balance += amount
|
34
|
-
puts "\tAccount(\##{account_id}) received #{amount}€ from Account(\##{source_account.account_id})."
|
34
|
+
puts "\t\tAccount(\##{account_id}) received #{amount}€ from Account(\##{source_account.account_id})."
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,10 +39,11 @@ class MoneyTransferContext < DCI::Context
|
|
39
39
|
# Interactions
|
40
40
|
|
41
41
|
def run(amount=settings(:amount))
|
42
|
-
puts "
|
42
|
+
puts "\nMoney Transfer of #{amount}€ between Account(\##{source_account.account_id}) and Account(\##{target_account.account_id})"
|
43
|
+
puts "\tBalances Before: #{balances}"
|
43
44
|
source_account.run_transfer_of(amount)
|
44
45
|
target_account.run_transfer_of(amount)
|
45
|
-
puts "
|
46
|
+
puts "\tBalances After: #{balances}"
|
46
47
|
end
|
47
48
|
|
48
49
|
|
data/lib/dci-ruby/dci/context.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'dci-ruby/dci/role'
|
2
2
|
|
3
3
|
module DCI
|
4
|
-
|
5
4
|
class Context
|
6
5
|
|
7
6
|
class << self
|
@@ -54,8 +53,8 @@ module DCI
|
|
54
53
|
new_roleklass = roles[new_rolekey]
|
55
54
|
mate_roles = mate_roles_of(new_rolekey)
|
56
55
|
mate_roles.each do |mate_rolekey, mate_roleklass|
|
57
|
-
mate_roleklass.add_role_reader_for
|
58
|
-
new_roleklass.add_role_reader_for
|
56
|
+
mate_roleklass.send(:add_role_reader_for!, new_rolekey)
|
57
|
+
new_roleklass.send(:add_role_reader_for!, mate_rolekey)
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
@@ -118,17 +117,5 @@ module DCI
|
|
118
117
|
instance_variable_set(:"@#{rolekey}", role_instance)
|
119
118
|
end
|
120
119
|
|
121
|
-
# # For each given pair in vars, define a private method named the key that returns the entry associated value.
|
122
|
-
# def define_readers_for_no_players(vars={})
|
123
|
-
# vars.each do |name, value|
|
124
|
-
# instance_variable_set(:"@#{name}", value)
|
125
|
-
# singleton_class.class_exec(name.to_sym) do |varkey|
|
126
|
-
# private
|
127
|
-
# attr_reader varkey
|
128
|
-
# end
|
129
|
-
# end
|
130
|
-
# end
|
131
|
-
|
132
120
|
end
|
133
|
-
|
134
121
|
end
|
data/lib/dci-ruby/dci/role.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'forwardable'
|
2
2
|
|
3
|
+
module DCI
|
3
4
|
class Role
|
4
5
|
extend ::Forwardable
|
5
6
|
|
@@ -11,29 +12,58 @@ module DCI
|
|
11
12
|
super
|
12
13
|
end
|
13
14
|
|
15
|
+
# Defines a public instance_method named role_method_name delegating its behaviour to player#player_methodname
|
16
|
+
# Ex: delegate_to_player :fullname, :name #=> def name(*args, &block)
|
17
|
+
# player.send(:fullname, *args, &block)
|
18
|
+
# end
|
14
19
|
def delegate_to_player(player_methodname, role_method_name = player_methodname)
|
15
20
|
class_eval("def #{role_method_name}(*args, &block); player.send(:#{player_methodname}, *args, &block) end")
|
16
21
|
end
|
17
22
|
|
23
|
+
# Defines a private instance_method named role_method_name delegating its behaviour to player#player_methodname
|
24
|
+
# Ex: delegate_to_player :fullname, :name #=> def name(*args, &block)
|
25
|
+
# player.send(:fullname, *args, &block)
|
26
|
+
# end
|
27
|
+
# private :name
|
18
28
|
def private_delegate_to_player(player_methodname, role_method_name = player_methodname)
|
19
29
|
delegate_to_player(player_methodname, role_method_name)
|
20
30
|
private role_method_name
|
21
31
|
end
|
22
32
|
|
33
|
+
# Defines multiple public instance_methods whose names are in the methodnames list
|
34
|
+
# delegating their behaviour to their counterparts in player.
|
35
|
+
# Ex: delegates_to_player :fullname, :age #=> def fullname(*args, &block)
|
36
|
+
# player.send(:fullname, *args, &block)
|
37
|
+
# end
|
38
|
+
# def age(*args, &block)
|
39
|
+
# player.send(:age, *args, &block)
|
40
|
+
# end
|
23
41
|
def delegates_to_player(*methodnames)
|
24
42
|
methodnames.each {|methodname| delegate_to_player(methodname)}
|
25
43
|
end
|
26
44
|
|
45
|
+
# Defines multiple private instance_methods whose names are in the methodnames list
|
46
|
+
# delegating their behaviour to their counterparts in player.
|
47
|
+
# Ex: private_delegates_to_player :fullname, :age #=> def fullname(*args, &block)
|
48
|
+
# player.send(:fullname, *args, &block)
|
49
|
+
# end
|
50
|
+
# def age(*args, &block)
|
51
|
+
# player.send(:age, *args, &block)
|
52
|
+
# end
|
53
|
+
# private :fullname, :age
|
27
54
|
def private_delegates_to_player(*methodnames)
|
28
55
|
methodnames.each {|methodname| private_delegate_to_player(methodname)}
|
29
56
|
end
|
30
57
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Defines a new private reader instance method for a context mate role, delegating it to the context object.
|
62
|
+
def add_role_reader_for!(rolekey)
|
63
|
+
return if private_method_defined?(rolekey)
|
64
|
+
define_method(rolekey) {@context.send(rolekey)}
|
65
|
+
private rolekey
|
66
|
+
end
|
37
67
|
|
38
68
|
end
|
39
69
|
|
data/lib/dci-ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dci-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 2.1.
|
9
|
+
- 2
|
10
|
+
version: 2.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lorenzo Tello
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-11-12 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|