callchain 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f961badd05dcae2858d74eaf1568858199639b2
4
- data.tar.gz: e6aa34f668bf30cb4ac5e0556daa503d2c82f408
3
+ metadata.gz: 6bc6bb09b89dfb7e2aee6547fc8f028d394add77
4
+ data.tar.gz: adfbbf6e6b4cc55e59c894d8c0ba678fb121192c
5
5
  SHA512:
6
- metadata.gz: a7252499d454464a7c98ff023bc396d3f51852a5d93678ac6db575a82d3b245e2a4de0ce65e41c8e5c5cb6c14c0f729a61dbef351d8b4e20cd0160c96a367204
7
- data.tar.gz: 42320b9bc8c268ca4fa3ec32bea52b77f95a6d823a48fb6e09fc9f8c76b35af11de2fcacd766a31db689010b86ac0b5331a40f9457f5c527fe375a416a2cca88
6
+ metadata.gz: 97329693c349a921c2030225f3124c04441745ae7dfd880ebdbeb5c6f2275dedf19c06d20b4aae0d2a4e396abbe87c9cb8e625aa3d8e2a35d169f1591d79e0a2
7
+ data.tar.gz: 53e1a2775715457385ff6ef33e2b1528869ea035f5e3c3383ad758b3cd0e1a2ac2c50d4c742e104a188ffa3b8656f20c56035f533eb091d6afa9de395692f494
data/README.md CHANGED
@@ -72,6 +72,28 @@ Compose a CallChain of call chains because it exports `::call(object)`
72
72
  CompositeCallChain.call(Object.new)
73
73
  ```
74
74
 
75
+ ## CallChain::bind
76
+
77
+ ```ruby
78
+ class WrapToI
79
+ extend CallChain
80
+ use CallChain[:to_i]
81
+ end
82
+
83
+ WrapToI.call('1')
84
+ # => 1
85
+ ```
86
+
87
+ ```ruby
88
+ class WrapToI
89
+ extend CallChain
90
+ use CallChain.bind(:+, 1)
91
+ end
92
+
93
+ WrapToI.call(1)
94
+ # => 2
95
+ ```
96
+
75
97
  ## Contributing
76
98
 
77
99
  1. Fork it ( http://github.com/<my-github-username>/callchain/fork )
@@ -35,4 +35,12 @@ module CallChain
35
35
  end
36
36
  thing
37
37
  end
38
+
39
+ def self.[](key)
40
+ self.bind(key)
41
+ end
42
+
43
+ def self.bind(method_name, *args)
44
+ lambda { |thing| thing.send(method_name, *args) }
45
+ end
38
46
  end
@@ -1,3 +1,3 @@
1
1
  module Callchain
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'minitest/autorun'
2
+ require 'callchain'
3
+
4
+
5
+ class BindTest < Minitest::Test
6
+ def test_calls_method
7
+ chain_class = Class.new
8
+ chain_class.extend(CallChain)
9
+ chain_class.use CallChain[:to_i]
10
+ assert_equal 1, chain_class.call('1')
11
+ end
12
+
13
+ def test_binds_args
14
+ chain_class = Class.new
15
+ chain_class.extend(CallChain)
16
+ chain_class.use CallChain.bind(:+, 1)
17
+ assert_equal 2, chain_class.call(1)
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callchain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - csquared
@@ -53,6 +53,7 @@ files:
53
53
  - callchain.gemspec
54
54
  - lib/callchain.rb
55
55
  - lib/callchain/version.rb
56
+ - test/bind_test.rb
56
57
  - test/callchain_test.rb
57
58
  homepage: ''
58
59
  licenses:
@@ -79,4 +80,5 @@ signing_key:
79
80
  specification_version: 4
80
81
  summary: Simple, composable call chains
81
82
  test_files:
83
+ - test/bind_test.rb
82
84
  - test/callchain_test.rb