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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +28 -3
  4. data/lib/dispatio.rb +9 -3
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 681d0cd297c65b0faa322d9335759096fdc7f4d872fe92848dd8943c23e8e101
4
- data.tar.gz: 8785befaac8bed983b0142271a2f06422c0b34852621acabef8a8ed32e04af83
3
+ metadata.gz: a460ddbac24649ff60c70b11b27d766a2fb5a748d682ced095e9933604200a96
4
+ data.tar.gz: 6449b86f7f5269661ed558b37bc3752d91f24f3b4d875ddb561a59f1975ba862
5
5
  SHA512:
6
- metadata.gz: 335b97d8e0f88b17d625cb6885d4cea39539b23fde270ee70142ab8265fcc3fe8966dff3eee74214690e5ce38fb80ec8b8d28714948cd6df757b723cb3941bf6
7
- data.tar.gz: 288bf30fadd914780542e48b0e4836823b9bfa10d9a379ae96715bb0a60b39b4bca58027a4a73b3376287fc69e9ea29b691e5fc9284a8bedcf311e6ee5d69014
6
+ metadata.gz: 82ced686161c8adf45614813ad55425f473efbd8af2ebb1438739ab2570d76e0815fda45056b49aee9cede82139a15afa9ab9f85b4495e3c83bb4618a77b606c
7
+ data.tar.gz: ebf88bb77dcfeecbf073ab56d04543bfe5185b4a938082ab30fb7b3149d9f1fa49b73c0e95773e45cf33cd1a932d8ecd22c4b164f9448a322081d0723f46e042
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
  # dispatio GHANGELOG.md
3
3
 
4
4
 
5
+ ## dispatio 1.1.0 released 2026-09-12
6
+
7
+ * Focus on #call, alias #dispatch to it
8
+
9
+
5
10
  ## dispatio 1.0.0 released 2026-09-11
6
11
 
7
12
  * First release
data/README.md CHANGED
@@ -1,16 +1,27 @@
1
1
 
2
2
  # dispatio
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/dispatio.svg)](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(:nada, 'nemo') # ==> NoMethodError 'no :validate_nada method'
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.0.0'.freeze
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 dispatch(name, *args, **opts, &block)
31
+ def [](name)
32
32
 
33
- ( @table[name.to_s] ||
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dispatio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux