role_playing 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -5
- data/lib/role_playing/context.rb +4 -1
- data/lib/role_playing/version.rb +1 -1
- data/spec/role_playing/role_playing_spec.rb +6 -3
- metadata +1 -1
data/README.md
CHANGED
@@ -42,17 +42,18 @@ Using it is as simple as defining (usually) a context like so:
|
|
42
42
|
end
|
43
43
|
|
44
44
|
## inside a context, a role can be defined
|
45
|
-
## using the class method "role"
|
46
|
-
|
45
|
+
## using the class method "role", it's basically
|
46
|
+
## the same as using class SourceAccount < RolePlaying::Role
|
47
|
+
## but a nicer language and does the inheritance for us and -
|
48
|
+
## YES these should be constants, not strings or symbols
|
49
|
+
role SourceAccount do
|
47
50
|
def withdraw(amount)
|
48
51
|
self.amount=self.amount-amount
|
49
52
|
amount
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
53
|
-
|
54
|
-
## the RolePlaying::Context module
|
55
|
-
role :destination_account do
|
56
|
+
role DestinationAccount do
|
56
57
|
def deposit(amount)
|
57
58
|
self.amount=self.amount+amount
|
58
59
|
end
|
data/lib/role_playing/context.rb
CHANGED
@@ -4,10 +4,13 @@ module RolePlaying
|
|
4
4
|
base.extend(ClassMethods)
|
5
5
|
end
|
6
6
|
module ClassMethods
|
7
|
+
def const_missing(sym)
|
8
|
+
class_name = sym.to_s
|
9
|
+
end
|
7
10
|
def role(name, parent=nil, &block)
|
8
11
|
parent = parent || RolePlaying::Role
|
9
12
|
klass = Class.new(parent, &block)
|
10
|
-
|
13
|
+
const_set name, klass
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
data/lib/role_playing/version.rb
CHANGED
@@ -36,15 +36,18 @@ class MoneyTransferring
|
|
36
36
|
end
|
37
37
|
|
38
38
|
## inside a context, a role can be defined
|
39
|
-
## using the class method "role"
|
40
|
-
|
39
|
+
## using the class method "role", it's basically
|
40
|
+
## the same as using class SourceAccount < RolePlaying::Role
|
41
|
+
## but a nicer language and does the inheritance for us and -
|
42
|
+
## YES these should be constants, not strings or symbols
|
43
|
+
role SourceAccount do
|
41
44
|
def withdraw(amount)
|
42
45
|
self.amount=self.amount-amount
|
43
46
|
amount
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
|
-
role
|
50
|
+
role DestinationAccount do
|
48
51
|
def deposit(amount)
|
49
52
|
self.amount=self.amount+amount
|
50
53
|
end
|