dispatio 1.2.1 → 1.3.1

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 +12 -0
  3. data/README.md +29 -0
  4. data/lib/dispatio.rb +18 -6
  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: 3b6cf79388c0c16b4426bd468505d45a6eedbbc2390fb50697f63cee8af99713
4
+ data.tar.gz: 00fe5ae9bc2977ce43287fc60a0ac9a491d06e9509fff36a52da2d1f38f8e7c1
5
5
  SHA512:
6
- metadata.gz: '08a3866d4918d6124b60399e0657e3e307647635a0105c9ff2ed54cb679eee236854e7e68ef6bee18939997bf7700cbe50fec87120dbe022b9f6c314da57a81f'
7
- data.tar.gz: eb83b8f0fb6a6609f44e0f21333645269617c55dd952d43e85c6ae3a6800b020db65d606d629f4efc97e4d770472204a7c81d4a5f7e8bba29fc58b52c9c098f8
6
+ metadata.gz: bb8f9b11caf4963e478762b74d6a1ba89cde8dbff4ba9f873a77dad842456b9743fa0d9b138bd927565e86130fa74ec6ed3c5fadfd7a0177e09f00a49cc5ab44
7
+ data.tar.gz: 1f26367ca537b9013154371a69ebee31fdcb873fd7db9f9d16d373fa3e4e40e0108cf612630592de50fd45a4340c16c6a5039e1fa06bd6e3be2ccffa9adad1b4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
  # dispatio GHANGELOG.md
3
3
 
4
4
 
5
+ ## dispatio 1.3.1 released 2026-10-05
6
+
7
+ * Allow for `Dispatio.make_table(self, 'validate_', default: :x)`
8
+
9
+
10
+ ## dispatio 1.3.0 released 2026-10-02
11
+
12
+ * Introduce make_table() default: value option
13
+ * Introduce Dispatio::Table.names
14
+ * Introduce Dispatio::Table.include?(name)
15
+
16
+
5
17
  ## dispatio 1.2.1 released 2026-09-13
6
18
 
7
19
  * 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,17 +1,18 @@
1
1
 
2
2
  module Dispatio
3
3
 
4
- VERSION = '1.2.1'.freeze
4
+ VERSION = '1.3.1'.freeze
5
5
 
6
6
  class << self
7
7
 
8
- def make_table(point, prefix_or_opts)
8
+ def make_table(point, prefix_or_opts, opts1={})
9
9
 
10
10
  opts =
11
11
  case poo = prefix_or_opts
12
12
  when /\A_/ then { suffix: poo }
13
13
  when String then { prefix: poo }
14
14
  else poo; end
15
+ .merge(opts1)
15
16
 
16
17
  fail(
17
18
  ArgumentError,
@@ -59,16 +60,27 @@ module Dispatio
59
60
 
60
61
  m = self[name]
61
62
 
63
+ return m.call(*args, **opts, &block) if m
64
+
65
+ return @opts[:default] if @opts.has_key?(:default)
66
+
62
67
  fail(
63
68
  NoMethodError,
64
69
  @opts[:prefix] ?
65
70
  "no :#{@opts[:prefix]}#{name} method" :
66
- "no :#{name}#{@opts[:suffix]} method"
67
- ) unless m
68
-
69
- m.call(*args, **opts, &block)
71
+ "no :#{name}#{@opts[:suffix]} method")
70
72
  end
71
73
  alias dispatch call
74
+
75
+ def names
76
+
77
+ @table.keys
78
+ end
79
+
80
+ def include?(name)
81
+
82
+ @table.keys.include?(name.to_s)
83
+ end
72
84
  end
73
85
  end
74
86
 
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux