dispatio 1.2.1 → 1.3.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 +7 -0
  3. data/README.md +29 -0
  4. data/lib/dispatio.rb +16 -5
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1291fe6d6ec352d090a78afae44e98656c14026566448a039065f7b58cd9cdf2
4
- data.tar.gz: 4e70a7cfd9125425d432c70d5eeb3df8829163ce19496378db877b9e8e7edbd2
3
+ metadata.gz: dcd71077a687e29a3ad7bfafc139e64a02c228de8c0a9fa5d815d1e6cb6807d4
4
+ data.tar.gz: ffc9cae009b1d706d0c463cf8206173382dc0b7a3afd9c022711ecbada200613
5
5
  SHA512:
6
- metadata.gz: '08a3866d4918d6124b60399e0657e3e307647635a0105c9ff2ed54cb679eee236854e7e68ef6bee18939997bf7700cbe50fec87120dbe022b9f6c314da57a81f'
7
- data.tar.gz: eb83b8f0fb6a6609f44e0f21333645269617c55dd952d43e85c6ae3a6800b020db65d606d629f4efc97e4d770472204a7c81d4a5f7e8bba29fc58b52c9c098f8
6
+ metadata.gz: 0e56deb551614afeb997c6748a3a13c83c6d3be0baff7a7acc111aa363ecfab300fd74cc50f738918ec299d242b8d7a29bb6c8b204288e59bf010c49385cce7c
7
+ data.tar.gz: d442514097e44dfd9bf1bb82eac1bbc7c1550626d7fbcaa6714800d6dd4701708cbaa43bff50e2711d798aa1b0a99e9e97c0881d694346aa75d540fa85d0df31
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
  # dispatio GHANGELOG.md
3
3
 
4
4
 
5
+ ## dispatio 1.3.0 released 2026-10-02
6
+
7
+ * Introduce make_table() default: value option
8
+ * Introduce Dispatio::Table.names
9
+ * Introduce Dispatio::Table.include?(name)
10
+
11
+
5
12
  ## dispatio 1.2.1 released 2026-09-13
6
13
 
7
14
  * Accept implicit `_suffix`
data/README.md CHANGED
@@ -135,6 +135,35 @@ Bar.consume('bar', 'world') # ==> [ Bar, :vbar, 'world' ]
135
135
  Bar.consume(:nada, 'nemo') # ==> NoMethodError, 'no :validate_nada method'
136
136
  ```
137
137
 
138
+ ## the default: v option
139
+
140
+ ```ruby
141
+ class Bonk; class << self
142
+
143
+ def consume(name, data)
144
+
145
+ dtable.dispatch(name, data)
146
+ end
147
+
148
+ protected
149
+
150
+ def validate_foo(data); [ self, :vfoo, data ]; end
151
+
152
+ def dtable
153
+
154
+ @dtable ||=
155
+ Dispatio.make_table(self, prefix: 'validate_', default: :x)
156
+ end
157
+ end; end
158
+
159
+ Bonk.consume('foo', { text: 'blah blah' })
160
+ # => [ Bonk, :vfoo, { text: 'blah blah' } ]
161
+ Bonk.consume(:foo, { text: 'bullsh*t' })
162
+ # => [ Bonk, :vfoo, { text: 'bullsh*t' } ]
163
+ Bonk.consume(:bar, { text: 'prank' })
164
+ # => :x
165
+ ```
166
+
138
167
 
139
168
  ## LICENSE
140
169
 
data/lib/dispatio.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Dispatio
3
3
 
4
- VERSION = '1.2.1'.freeze
4
+ VERSION = '1.3.0'.freeze
5
5
 
6
6
  class << self
7
7
 
@@ -59,16 +59,27 @@ module Dispatio
59
59
 
60
60
  m = self[name]
61
61
 
62
+ return m.call(*args, **opts, &block) if m
63
+
64
+ return @opts[:default] if @opts.has_key?(:default)
65
+
62
66
  fail(
63
67
  NoMethodError,
64
68
  @opts[:prefix] ?
65
69
  "no :#{@opts[:prefix]}#{name} method" :
66
- "no :#{name}#{@opts[:suffix]} method"
67
- ) unless m
68
-
69
- m.call(*args, **opts, &block)
70
+ "no :#{name}#{@opts[:suffix]} method")
70
71
  end
71
72
  alias dispatch call
73
+
74
+ def names
75
+
76
+ @table.keys
77
+ end
78
+
79
+ def include?(name)
80
+
81
+ @table.keys.include?(name.to_s)
82
+ end
72
83
  end
73
84
  end
74
85
 
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.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux