greedy-dci 1.1.0 → 1.1.1
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/.gitignore +1 -0
- data/README.md +21 -1
- data/examples/money_transfer.rb +38 -0
- data/examples/toy_shop.rb +1 -1
- data/lib/greedy/dci/context.rb +4 -0
- data/lib/greedy/dci/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dadf94d664eb773729fb06cb16229531108feee
|
4
|
+
data.tar.gz: e9d0ef566e82cb1554fe9e46ddf74a21994f3222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c65bad34b11c705aa501d348ad409a1e272d8552f566cb8fbcf5b8856ea3a77494a6d6e899f9104828c464aaa5fe602f4cd8cb59fdcbb7e34e77233ab102530c
|
7
|
+
data.tar.gz: a784e1227ac52de165753cf30e053e4d05b183bc02f756d02a6372239a74421c8d337068b3816d848ce4d6b237dee3d913acace036915d89e7b0b97645603c1b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Greedy::DCI
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/greedy-dci)
|
4
|
+
|
3
5
|
A Toolkit for rapid prototyping of interactors, use cases and service objects, using the DCI paradigm.
|
4
6
|
This implementation consumes excessive resources (hence the name) and is **not recommended for production use**.
|
5
7
|
|
@@ -33,7 +35,7 @@ Or install it yourself as:
|
|
33
35
|
## Usage
|
34
36
|
|
35
37
|
```ruby
|
36
|
-
require 'greedy
|
38
|
+
require 'greedy/dci'
|
37
39
|
|
38
40
|
# Data
|
39
41
|
|
@@ -89,6 +91,24 @@ finn_purchase_toy['The Enchiridion']
|
|
89
91
|
|
90
92
|
[View more examples](https://github.com/RichOrElse/greedy-dci/tree/master/examples)
|
91
93
|
|
94
|
+
## Context methods
|
95
|
+
|
96
|
+
### to_proc
|
97
|
+
|
98
|
+
Returns call method as a Proc.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
['Card Wars', 'Ice Ninja Manual', 'Bacon'].map &GiftToy[gifter: 'Jake', giftee: 'Finn']
|
102
|
+
```
|
103
|
+
|
104
|
+
### context[params,...]
|
105
|
+
|
106
|
+
Square brackets are alias for call method.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
TransferMoney[from: source_account, to: destination_account][amount: 100]
|
110
|
+
```
|
111
|
+
|
92
112
|
## Development
|
93
113
|
|
94
114
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# See https://github.com/RichOrElse/greedy-dci/blob/master/test/money_transfer_test.rb
|
2
|
+
|
3
|
+
Log = method(:puts)
|
4
|
+
Account = Struct.new(:number, :balance)
|
5
|
+
NotEnoughFund = Class.new(StandardError)
|
6
|
+
|
7
|
+
module SourceAccount
|
8
|
+
def decrease_balance_by(amount)
|
9
|
+
raise NotEnoughFund, "Balance is below amount.", caller if balance < amount
|
10
|
+
self.balance -= amount
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module DestinationAccount
|
15
|
+
def increase_balance_by(amount)
|
16
|
+
self.balance += amount
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
TransferMoney = Greedy.context do |from, to|
|
21
|
+
using from.as SourceAccount
|
22
|
+
using to.as DestinationAccount
|
23
|
+
|
24
|
+
def withdraw(amount)
|
25
|
+
from.decrease_balance_by(amount)
|
26
|
+
Log["Withdraw", amount, from]
|
27
|
+
end
|
28
|
+
|
29
|
+
def deposit(amount)
|
30
|
+
to.increase_balance_by(amount)
|
31
|
+
Log["Deposit", amount, to]
|
32
|
+
end
|
33
|
+
|
34
|
+
def call(amount:)
|
35
|
+
withdraw(amount)
|
36
|
+
deposit(amount)
|
37
|
+
end
|
38
|
+
end
|
data/examples/toy_shop.rb
CHANGED
data/lib/greedy/dci/context.rb
CHANGED
data/lib/greedy/dci/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greedy-dci
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ritchie Paul Buitre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- bin/setup
|
73
73
|
- examples/dijkstra.rb
|
74
74
|
- examples/dijkstra/data.rb
|
75
|
+
- examples/money_transfer.rb
|
75
76
|
- examples/toy_shop.rb
|
76
77
|
- greedy-dci.gemspec
|
77
78
|
- lib/greedy/dci.rb
|