rietveld 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/lib/rietveld/context.rb +35 -1
- data/lib/rietveld/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac3e2eb52b3a53b32027a8eab25b6307737d5eb2
|
4
|
+
data.tar.gz: c8ccea1342c286f00a12fc65a77f41a61d35d5b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b60efac74b799d93b86244d220ab46099e67698496714570a245ec5dd90c39a438932748eef08ad8aa5cbe6bb88f1412401c56743c7844fd9805a058987fe5a3
|
7
|
+
data.tar.gz: 3382f09d51a3ae6b71fae879b0212d862343b34e520b04fd64a8a59bddc2a1512779aaf8b5f2b601b3d1f7264b28e75632b38b8e5fdef6648eade4c382dbf473
|
data/README.md
CHANGED
@@ -11,3 +11,35 @@ And then execute:
|
|
11
11
|
Or install it yourself as:
|
12
12
|
|
13
13
|
$ gem install rietveld
|
14
|
+
|
15
|
+
|
16
|
+
## Example
|
17
|
+
|
18
|
+
``` ruby
|
19
|
+
class MoneyTransferContext < Rietveld::Context
|
20
|
+
role :source_account do
|
21
|
+
def withdraw(amount)
|
22
|
+
if balance >= amount
|
23
|
+
decrease_balance(amount)
|
24
|
+
amount
|
25
|
+
else
|
26
|
+
raise 'Insufficient funds'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def transfer(amount)
|
31
|
+
destination_account.deposit(withdraw(amount))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
role :destination_account do
|
36
|
+
def deposit(amount)
|
37
|
+
increase_balance(amount)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def transfer(amount)
|
42
|
+
source_account.transfer(amount)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
data/lib/rietveld/context.rb
CHANGED
@@ -1,4 +1,38 @@
|
|
1
|
-
module Rietveld
|
1
|
+
module Rietveld # :nodoc:
|
2
|
+
|
3
|
+
##
|
4
|
+
# The Context class supplies a simple DSL for creating roles and interaction
|
5
|
+
# between those roles
|
6
|
+
#
|
7
|
+
# An example:
|
8
|
+
#
|
9
|
+
# class MoneyTransferContext < Rietveld::Context
|
10
|
+
# role :source_account do
|
11
|
+
# def withdraw(amount)
|
12
|
+
# if balance >= amount
|
13
|
+
# decrease_balance(amount)
|
14
|
+
# amount
|
15
|
+
# else
|
16
|
+
# raise 'Insufficient funds'
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def transfer(amount)
|
21
|
+
# destination_account.deposit(withdraw(amount))
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# role :destination_account do
|
26
|
+
# def deposit(amount)
|
27
|
+
# increase_balance(amount)
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# def transfer(amount)
|
32
|
+
# source_account.transfer(amount)
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
2
36
|
class Context
|
3
37
|
class << self
|
4
38
|
def roles
|
data/lib/rietveld/version.rb
CHANGED