dispatio 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 681d0cd297c65b0faa322d9335759096fdc7f4d872fe92848dd8943c23e8e101
4
+ data.tar.gz: 8785befaac8bed983b0142271a2f06422c0b34852621acabef8a8ed32e04af83
5
+ SHA512:
6
+ metadata.gz: 335b97d8e0f88b17d625cb6885d4cea39539b23fde270ee70142ab8265fcc3fe8966dff3eee74214690e5ce38fb80ec8b8d28714948cd6df757b723cb3941bf6
7
+ data.tar.gz: 288bf30fadd914780542e48b0e4836823b9bfa10d9a379ae96715bb0a60b39b4bca58027a4a73b3376287fc69e9ea29b691e5fc9284a8bedcf311e6ee5d69014
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+
2
+ # dispatio GHANGELOG.md
3
+
4
+
5
+ ## dispatio 1.0.0 released 2026-09-11
6
+
7
+ * First release
8
+
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+
2
+ Copyright (c) 2026-2026, John Mettraux, jmettraux+flor@gmail.com
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+
22
+
23
+ Made in Japan
24
+
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+
2
+ # dispatio
3
+
4
+ A stupid dispatch table tool.
5
+
6
+ ## against an instance
7
+
8
+ ```ruby
9
+ class Foo
10
+
11
+ def consume(name, data)
12
+
13
+ dtable.dispatch(name, data)
14
+ end
15
+
16
+ protected
17
+
18
+ def validate_foo(data)
19
+ [ self.class, :vfoo, data ]
20
+ end
21
+
22
+ def validate_bar(data)
23
+ [ self.class, :vbar, data ]
24
+ end
25
+
26
+ def dtable; @dtable ||= Dispatio.make_table(self, 'validate_'); end
27
+ end
28
+
29
+ foo = Foo.new
30
+
31
+ foo.consume(:foo, 'hello') # ==> [ Foo, :vfoo, 'hello' ]
32
+ foo.consume(:bar, 'world') # ==> [ Foo, :vbar, 'world' ]
33
+
34
+ foo.consume(:nada, 'nemo') # ==> NoMethodError 'no :validate_nada method'
35
+ ```
36
+
37
+ ## against a singleton class
38
+
39
+ ```ruby
40
+ class Bar
41
+
42
+ class << self
43
+
44
+ def consume(name, data)
45
+
46
+ dtable.dispatch(name, data)
47
+ end
48
+
49
+ protected
50
+
51
+ def validate_foo(data)
52
+ [ self, :vfoo, data ]
53
+ end
54
+
55
+ def validate_bar(data)
56
+ [ self, :vbar, data ]
57
+ end
58
+
59
+ def dtable; @dtable ||= Dispatio.make_table(self, 'validate_'); end
60
+ end
61
+ end
62
+
63
+ Bar.consume(:foo, 'hello') # ==> [ Bar, :vfoo, 'hello' ]
64
+ Bar.consume(:bar, 'world') # ==> [ Bar, :vbar, 'world' ]
65
+
66
+ Bar.consume(:nada, 'nemo') # ==> NoMethodError, 'no :validate_nada method'
67
+ ```
68
+
69
+
70
+ ## LICENSE
71
+
72
+ MIT, see [LICENSE.txt](LICENSE.txt)
73
+
data/dispatio.gemspec ADDED
@@ -0,0 +1,50 @@
1
+
2
+ Gem::Specification.new do |s|
3
+
4
+ s.name = 'dispatio'
5
+
6
+ s.version = File.read(
7
+ File.expand_path("../lib/#{s.name}.rb", __FILE__)
8
+ ).match(/ VERSION *= *['"]([^'"]+)/)[1]
9
+
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = [ 'John Mettraux' ]
12
+ s.email = [ 'jmettraux+flor@gmail.com' ]
13
+ s.homepage = "https://github.com/floraison/#{s.name}"
14
+ s.license = 'MIT'
15
+ s.summary = 'a stupid dispatch table tool'
16
+
17
+ s.description = %{
18
+ A stupid dispatch table for convenience.
19
+ }.strip
20
+
21
+ s.metadata = {
22
+ 'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
23
+ 'bug_tracker_uri' => s.homepage + '/issues',
24
+ 'documentation_uri' => s.homepage,
25
+ 'homepage_uri' => s.homepage,
26
+ 'source_code_uri' => s.homepage,
27
+ #'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
28
+ #'wiki_uri' => s.homepage + '/wiki',
29
+ 'rubygems_mfa_required' => 'true',
30
+ }
31
+
32
+ #s.files = `git ls-files`.split("\n")
33
+ s.files = Dir[
34
+ '{README,CHANGELOG,CREDITS,LICENSE}.{md,txt}',
35
+ #'Makefile',
36
+ 'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
37
+ "#{s.name}.gemspec",
38
+ ]
39
+
40
+ #s.add_runtime_dependency 'tzinfo'
41
+ # this dependency appears in 'et-orbi'
42
+
43
+ #s.add_runtime_dependency 'raabro', '~> 1.4'
44
+
45
+ #s.add_development_dependency 'rspec', '~> 3.8'
46
+ s.add_development_dependency 'probatio', '~> 1.6'
47
+
48
+ s.require_path = 'lib'
49
+ end
50
+
data/lib/dispatio.rb ADDED
@@ -0,0 +1,39 @@
1
+
2
+ module Dispatio
3
+
4
+ VERSION = '1.0.0'.freeze
5
+
6
+ class << self
7
+
8
+ def make_table(point, prefix)
9
+
10
+ Dispatio::Table.new(
11
+ prefix,
12
+ point
13
+ .methods
14
+ .select { |m|
15
+ m.to_s.start_with?(prefix) }
16
+ .inject({}) { |h, m|
17
+ h[m.to_s[prefix.length..-1]] = point.method(m)
18
+ h }
19
+ ).freeze
20
+ end
21
+ end
22
+
23
+ class Table
24
+
25
+ def initialize(prefix, table)
26
+
27
+ @prefix = prefix
28
+ @table = table.freeze
29
+ end
30
+
31
+ def dispatch(name, *args, **opts, &block)
32
+
33
+ ( @table[name.to_s] ||
34
+ fail(NoMethodError.new("no :#{@prefix}#{name} method"))
35
+ ).call(*args, **opts, &block)
36
+ end
37
+ end
38
+ end
39
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dispatio
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John Mettraux
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: probatio
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.6'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.6'
26
+ description: A stupid dispatch table for convenience.
27
+ email:
28
+ - jmettraux+flor@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - LICENSE.txt
35
+ - README.md
36
+ - dispatio.gemspec
37
+ - lib/dispatio.rb
38
+ homepage: https://github.com/floraison/dispatio
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ changelog_uri: https://github.com/floraison/dispatio/blob/master/CHANGELOG.md
43
+ bug_tracker_uri: https://github.com/floraison/dispatio/issues
44
+ documentation_uri: https://github.com/floraison/dispatio
45
+ homepage_uri: https://github.com/floraison/dispatio
46
+ source_code_uri: https://github.com/floraison/dispatio
47
+ rubygems_mfa_required: 'true'
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.6.9
63
+ specification_version: 4
64
+ summary: a stupid dispatch table tool
65
+ test_files: []