dispatio 1.0.0 → 1.1.0
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/CHANGELOG.md +5 -0
- data/README.md +28 -3
- data/lib/dispatio.rb +9 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a460ddbac24649ff60c70b11b27d766a2fb5a748d682ced095e9933604200a96
|
|
4
|
+
data.tar.gz: 6449b86f7f5269661ed558b37bc3752d91f24f3b4d875ddb561a59f1975ba862
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82ced686161c8adf45614813ad55425f473efbd8af2ebb1438739ab2570d76e0815fda45056b49aee9cede82139a15afa9ab9f85b4495e3c83bb4618a77b606c
|
|
7
|
+
data.tar.gz: ebf88bb77dcfeecbf073ab56d04543bfe5185b4a938082ab30fb7b3149d9f1fa49b73c0e95773e45cf33cd1a932d8ecd22c4b164f9448a322081d0723f46e042
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
|
|
2
2
|
# dispatio
|
|
3
3
|
|
|
4
|
+
[](http://badge.fury.io/rb/dispatio)
|
|
5
|
+
|
|
4
6
|
A stupid dispatch table tool.
|
|
5
7
|
|
|
8
|
+
|
|
6
9
|
## against an instance
|
|
7
10
|
|
|
8
11
|
```ruby
|
|
12
|
+
require 'dispatio'
|
|
13
|
+
|
|
9
14
|
class Foo
|
|
10
15
|
|
|
11
16
|
def consume(name, data)
|
|
12
17
|
|
|
13
|
-
dtable.dispatch(name, data)
|
|
18
|
+
dtable.dispatch(name, data) # or
|
|
19
|
+
#dtable.call(name, data) #
|
|
20
|
+
#dtable.(name, data) #
|
|
21
|
+
#dtable[name].call(data) # or
|
|
22
|
+
#dtable[name].(data) #
|
|
23
|
+
#
|
|
24
|
+
# just use the one you like
|
|
14
25
|
end
|
|
15
26
|
|
|
16
27
|
protected
|
|
@@ -31,19 +42,30 @@ foo = Foo.new
|
|
|
31
42
|
foo.consume(:foo, 'hello') # ==> [ Foo, :vfoo, 'hello' ]
|
|
32
43
|
foo.consume(:bar, 'world') # ==> [ Foo, :vbar, 'world' ]
|
|
33
44
|
|
|
34
|
-
foo.consume(
|
|
45
|
+
foo.consume('foo', 'hello') # ==> [ Foo, :vfoo, 'hello' ]
|
|
46
|
+
foo.consume('bar', 'world') # ==> [ Foo, :vbar, 'world' ]
|
|
47
|
+
|
|
48
|
+
foo.consume(:nada, 'nemo') # ==> NoMethodError, 'no :validate_nada method'
|
|
35
49
|
```
|
|
36
50
|
|
|
37
51
|
## against a singleton class
|
|
38
52
|
|
|
39
53
|
```ruby
|
|
54
|
+
require 'dispatio'
|
|
55
|
+
|
|
40
56
|
class Bar
|
|
41
57
|
|
|
42
58
|
class << self
|
|
43
59
|
|
|
44
60
|
def consume(name, data)
|
|
45
61
|
|
|
46
|
-
dtable.dispatch(name, data)
|
|
62
|
+
dtable.dispatch(name, data) # or
|
|
63
|
+
#dtable.call(name, data) #
|
|
64
|
+
#dtable.(name, data) #
|
|
65
|
+
#dtable[name].call(data) # or
|
|
66
|
+
#dtable[name].(data) #
|
|
67
|
+
#
|
|
68
|
+
# just use the one you like
|
|
47
69
|
end
|
|
48
70
|
|
|
49
71
|
protected
|
|
@@ -63,6 +85,9 @@ end
|
|
|
63
85
|
Bar.consume(:foo, 'hello') # ==> [ Bar, :vfoo, 'hello' ]
|
|
64
86
|
Bar.consume(:bar, 'world') # ==> [ Bar, :vbar, 'world' ]
|
|
65
87
|
|
|
88
|
+
Bar.consume('foo', 'hello') # ==> [ Bar, :vfoo, 'hello' ]
|
|
89
|
+
Bar.consume('bar', 'world') # ==> [ Bar, :vbar, 'world' ]
|
|
90
|
+
|
|
66
91
|
Bar.consume(:nada, 'nemo') # ==> NoMethodError, 'no :validate_nada method'
|
|
67
92
|
```
|
|
68
93
|
|
data/lib/dispatio.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
module Dispatio
|
|
3
3
|
|
|
4
|
-
VERSION = '1.
|
|
4
|
+
VERSION = '1.1.0'.freeze
|
|
5
5
|
|
|
6
6
|
class << self
|
|
7
7
|
|
|
@@ -28,12 +28,18 @@ module Dispatio
|
|
|
28
28
|
@table = table.freeze
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def
|
|
31
|
+
def [](name)
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
@table[name.to_s]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def call(name, *args, **opts, &block)
|
|
37
|
+
|
|
38
|
+
( self[name] ||
|
|
34
39
|
fail(NoMethodError.new("no :#{@prefix}#{name} method"))
|
|
35
40
|
).call(*args, **opts, &block)
|
|
36
41
|
end
|
|
42
|
+
alias dispatch call
|
|
37
43
|
end
|
|
38
44
|
end
|
|
39
45
|
|