greedy-dci 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a34f8a8ef376678a0f08acf617f642e42c4e615e
4
- data.tar.gz: b3939923c99ebe57d06e5f1ffb4f4afd6d44dfc0
3
+ metadata.gz: 8dadf94d664eb773729fb06cb16229531108feee
4
+ data.tar.gz: e9d0ef566e82cb1554fe9e46ddf74a21994f3222
5
5
  SHA512:
6
- metadata.gz: 066376ec6fe3c31aa3368279979d86854f45a4166f4d68473c4e128f1184e1689d762f81f31dcc74d62ed0d061917fef8b7ac3b7effda31ecc7411224f69b0fe
7
- data.tar.gz: a5a3d657e5980fe7caa331447e55b89c57654eeefea7958a0f715accb45c5437155b249a3ceb636ef90938a9b107fec33adcb4aea2c0d6345f71ebcae8793c80
6
+ metadata.gz: c65bad34b11c705aa501d348ad409a1e272d8552f566cb8fbcf5b8856ea3a77494a6d6e899f9104828c464aaa5fe602f4cd8cb59fdcbb7e34e77233ab102530c
7
+ data.tar.gz: a784e1227ac52de165753cf30e053e4d05b183bc02f756d02a6372239a74421c8d337068b3816d848ce4d6b237dee3d913acace036915d89e7b0b97645603c1b
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Greedy::DCI
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/greedy-dci.svg)](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-dci'
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
@@ -1,4 +1,4 @@
1
- require 'greedy-dci'
1
+ require 'greedy/dci'
2
2
 
3
3
  # Data
4
4
 
@@ -4,6 +4,10 @@ module Greedy
4
4
  def to_proc
5
5
  method(:call).to_proc
6
6
  end
7
+
8
+ def [](*args)
9
+ call(*args)
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,5 +1,5 @@
1
1
  module Greedy
2
2
  module DCI
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
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.0
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-13 00:00:00.000000000 Z
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