wrapper_based 0.2.0 → 0.3.0

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: 3884a927dc98c62e687795e8c27adab6da2cbd4d
4
- data.tar.gz: 7f2e1cc4a16a2dcd87dad76824e16def53960f4c
3
+ metadata.gz: 860bb92daa686c64bcb7807cc743a0e1f41d892d
4
+ data.tar.gz: 15482c725f191bc7fa9a336fddebbc10e71a3051
5
5
  SHA512:
6
- metadata.gz: 3e83ede5eaf7bbedc6934315fa6174356bcf86e3812016c58aef1f4963a6b03b7025af2aa9414cc0208c6297b15c9e580ebab72c83acfb7a408adf5eb1dbd0b1
7
- data.tar.gz: 4fa65380623ebbad5fd2b90e468a92afeab6581e692ff272345c99e70e15091ecd5e41f0280953493e8f445e61e71965a118b499ac4e564031760216f36c3ecc
6
+ metadata.gz: ab743403db24d5918f180321e2c6f45c93f5284c7d9bfab97038cf19b399abcb2d0f28870e98db9d0dc854d99e79a1afafa38e35288ccdb3c63285ab6718fbcb
7
+ data.tar.gz: 817c1a3a8494e3d259df6602f59eaf15a6931208ea530333201895dc8c8c1bb124160e4e75712ca62bb675ca515654330a6d1795bc700949af2096a4b950012a
data/README.md CHANGED
@@ -60,12 +60,12 @@ DCI = WrapperBased::DCI.new unless defined? DCI
60
60
  class Distance < DCI::Context(:within)
61
61
  within.as Map
62
62
 
63
- def between(a, b)
64
- within.distance_between(a, b)
63
+ def between(from, to)
64
+ within.distance_between(from, to)
65
65
  end
66
66
 
67
67
  def of(path)
68
- path.reverse.each_cons(2).inject(0) { |total, pair| total + between(*pair) }
68
+ path.reverse.each_cons(2).inject(0) { |total_distance, pair| total_distance + between(*pair) }
69
69
  end
70
70
  end
71
71
 
@@ -92,8 +92,27 @@ class Shortest < DCI::Context(:from, :to, :city)
92
92
  end
93
93
  end
94
94
  ```
95
+
95
96
  [View more examples](https://github.com/RichOrElse/wrapper-based/tree/master/examples)
96
97
 
98
+ ## Context methods
99
+
100
+ ### to_proc
101
+
102
+ Returns call method as a Proc.
103
+
104
+ ```ruby
105
+ ['Card Wars', 'Ice Ninja Manual', 'Bacon'].map &GiftToy[gifter: 'Jake', giftee: 'Finn']
106
+ ```
107
+
108
+ ### context[params,...]
109
+
110
+ Square brackets are alias for call method.
111
+
112
+ ```ruby
113
+ TransferMoney[from: source_account, to: destination_account][amount: 100]
114
+ ```
115
+
97
116
  ## Development
98
117
 
99
118
  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.
data/examples/dijkstra.rb CHANGED
@@ -35,12 +35,12 @@ DCI = WrapperBased::DCI.new unless defined? DCI
35
35
  class Distance < DCI::Context(:within)
36
36
  within.as Map
37
37
 
38
- def between(a, b)
39
- within.distance_between(a, b)
38
+ def between(from, to)
39
+ within.distance_between(from, to)
40
40
  end
41
41
 
42
42
  def of(path)
43
- path.reverse.each_cons(2).inject(0) { |total, pair| total + between(*pair) }
43
+ path.reverse.each_cons(2).inject(0) { |total_distance, pair| total_distance + between(*pair) }
44
44
  end
45
45
  end
46
46
 
@@ -1,10 +1,10 @@
1
1
  Log = method(:puts)
2
2
  Account = Struct.new(:number, :balance)
3
- NotEnoughFund = Class.new(StandardError)
3
+ NotEnoughFunds = Class.new(StandardError)
4
4
 
5
5
  module SourceAccount
6
6
  def decrease_balance_by(amount)
7
- raise NotEnoughFund, "Balance is below amount.", caller if balance < amount
7
+ raise NotEnoughFunds, "Balance is below amount.", caller if balance < amount
8
8
  self.balance -= amount
9
9
  end
10
10
  end
@@ -4,6 +4,14 @@ module WrapperBased
4
4
  where.each { |role, player| instance_variable_set :"@#{role}", player }
5
5
  end
6
6
 
7
+ def to_proc
8
+ method(:call).to_proc
9
+ end
10
+
11
+ def [](*args, &block)
12
+ call(*args, &block)
13
+ end
14
+
7
15
  class << self
8
16
  def [](**role_cast, &block)
9
17
  context_class = Class.new(self, &block)
@@ -1,3 +1,3 @@
1
1
  module WrapperBased
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrapper_based
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ritchie Paul Buitre