procto_coverhound 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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +54 -0
  4. data/lib/procto/version.rb +6 -0
  5. data/lib/procto.rb +114 -0
  6. metadata +55 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1ec4c9a1581e30fdf201d5ff2836913708184d4f29e5e31cb80071ee66c6ea35
4
+ data.tar.gz: 4ed7f52176f8842fbb094246342225cefbe2ba2d6f2087109b5ca1a439b0cced
5
+ SHA512:
6
+ metadata.gz: ab7ad81ab23caf1f252a0730a632cfa813d98d45ba0af5f0f4189a3008d1768c173213473346ad478b806268d412c4026038a41adf034c8801ac6323cf40dc39
7
+ data.tar.gz: 2dd8b34150250c1afc72a80544e3fc2126d03386e15709f8ab4ebf85e7222897f70e6996d450b614796af0d8ba3bf4dd54023e162ddc46858665f6720b5a3351
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2026 CoverHound
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # procto
2
+
3
+ Method objects. CoverHound wanted to specify method names sometimes, so we spun
4
+ this off.
5
+
6
+ ## Usage
7
+
8
+ ```ruby
9
+ require 'procto'
10
+
11
+ class Greeter
12
+ include Procto.call
13
+
14
+ def initialize(text)
15
+ @text = text
16
+ end
17
+
18
+ def call
19
+ "Hello #{text}"
20
+ end
21
+
22
+ private
23
+ attr_reader :text
24
+ end
25
+
26
+ Greeter.call('world') # => "Hello world"
27
+
28
+ class Printer
29
+ include Procto.call(:print)
30
+
31
+ def initialize(text)
32
+ @text = text
33
+ end
34
+
35
+ def print
36
+ "Hello #{text}"
37
+ end
38
+
39
+ private
40
+ attr_reader :text
41
+ end
42
+
43
+ Printer.print('world') # => "Hello world"
44
+ ```
45
+
46
+ ## Credits
47
+
48
+ * [snusnu](https://github.com/snusnu)
49
+ * [mbj](https://github.com/mbj)
50
+ * [supernats](https://github.com/supernats)
51
+
52
+ ## Copyright
53
+
54
+ Copyright © 2026 CoverHound. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Procto < Module
4
+ # Gem version
5
+ VERSION = '1.0.0'
6
+ end
data/lib/procto.rb ADDED
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Procto < Module
4
+ # The default name of the instance method to be called
5
+ DEFAULT_NAME = :call
6
+
7
+ private_class_method :new
8
+
9
+ # Return a module that turns the host into a method object
10
+ #
11
+ # @example without a name
12
+ #
13
+ # class Greeter
14
+ # include Procto.call
15
+ #
16
+ # def initialize(text)
17
+ # @text = text
18
+ # end
19
+ #
20
+ # def call
21
+ # "Hello #{text}"
22
+ # end
23
+ # end
24
+ #
25
+ # Greeter.call('world') # => "Hello world"
26
+ #
27
+ # @example with a name
28
+ #
29
+ # class Printer
30
+ # include Procto.call(:print)
31
+ #
32
+ # def initialize(text)
33
+ # @text = text
34
+ # end
35
+ #
36
+ # def print
37
+ # "Hello #{text}"
38
+ # end
39
+ # end
40
+ #
41
+ # Printer.call('world') # => "Hello world"
42
+ #
43
+ # @param [#to_sym] name
44
+ # the name of the instance method to call
45
+ #
46
+ # @return [Procto]
47
+ #
48
+ # @api public
49
+ def self.call(name = DEFAULT_NAME)
50
+ new(name.to_sym)
51
+ end
52
+
53
+ # Initialize a new instance
54
+ #
55
+ # @param [Symbol] name
56
+ # the name of the instance method to call
57
+ #
58
+ # @return [undefined]
59
+ #
60
+ # @api private
61
+ def initialize(name)
62
+ @name = name
63
+ @block = ->(*args, **kwargs, &block) { new(*args, **kwargs, &block).public_send(name) }
64
+ end
65
+
66
+ private
67
+
68
+ # Define the .call method on +host+
69
+ #
70
+ # @param [Object] host
71
+ # the hosting object
72
+ #
73
+ # @return [undefined]
74
+ #
75
+ # @api private
76
+ def included(host)
77
+ host.instance_exec(@block, @name) do |block, method_name|
78
+ define_singleton_method(:call, &block)
79
+ define_singleton_method(method_name, &block) if method_name && method_name != :call
80
+ end
81
+
82
+ host.extend(ClassMethods)
83
+ end
84
+
85
+ # Procto module for adding .to_proc to host class
86
+ module ClassMethods
87
+ # Return the `call` singleton method as a lambda
88
+ #
89
+ # @example using a class as a proc
90
+ #
91
+ # class Shouter
92
+ # include Procto.call
93
+ #
94
+ # def initialize(text)
95
+ # @text = text
96
+ # end
97
+ #
98
+ # def call
99
+ # "#{@text.upcase}!"
100
+ # end
101
+ # end
102
+ #
103
+ # Shouter.to_proc.call('hello') # => "HELLO!"
104
+ # %w[foo bar].map(&Shouter) # => ["FOO!", "BAR!"]
105
+ #
106
+ # @return [Proc]
107
+ #
108
+ # @api public
109
+ def to_proc
110
+ public_method(:call).to_proc
111
+ end
112
+ end
113
+ private_constant(:ClassMethods)
114
+ end # Procto
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: procto_coverhound
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Gamsjaeger (snusnu)
8
+ - Nathan Seither (Supernats)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2026-01-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: 'Turns your object into a method object.
15
+
16
+ '
17
+ email: eng-admin@coverhound.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - LICENSE
22
+ - README.md
23
+ files:
24
+ - LICENSE
25
+ - README.md
26
+ - lib/procto.rb
27
+ - lib/procto/version.rb
28
+ homepage: https://github.com/coverhound/procto_coverhound
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '4.1'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.4.19
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Defines Foo.call(*args) which invokes Foo.new(*args).call. You can also define
54
+ a Foo.bar(*args) which invokes Foo.new(*args).bar.
55
+ test_files: []