to_proc_interface 0.1.1 → 0.2.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 +4 -4
- data/.rubocop.yml +19 -0
- data/CHANGELOG.md +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/Rakefile +5 -1
- data/lib/to_proc_interface/call_to_maybe.rb +16 -0
- data/lib/to_proc_interface/calling_service.rb +27 -0
- data/lib/to_proc_interface/hooks.rb +102 -0
- data/lib/to_proc_interface/initializer.rb +21 -0
- data/lib/to_proc_interface/performing_service.rb +27 -0
- data/lib/to_proc_interface/singleton.rb +47 -0
- data/lib/to_proc_interface/version.rb +2 -2
- data/lib/to_proc_interface/wrapping_call.rb +28 -0
- data/lib/to_proc_interface.rb +100 -195
- metadata +21 -12
- data/sig/to_proc_interface.rbs +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b002618fc6a3b5e2e6d7a7d649a093b4f053fc4d9020ff4a19cb27213ee8f882
|
4
|
+
data.tar.gz: 0d081f67681e258e9ef4d09b7e26f81f688ef8741bda45bda5477813e2a4c99b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 501d9ef19ae6a4051d59838a8fa1b480bb90574a76653e39662c1c78ec9458c9e81e13ca2ee2951bc1fa6c6f2a320c2da9a6c482b947d2a7ba969961cfb307d4
|
7
|
+
data.tar.gz: 923339620dfa4e87a3db869fe20c46d34bafc602e2d4a6b7e50b309be5272421a5e88f185ee36504f2cf1d34651a353aa9ab7eeb426702dd9251ef2a95ddbbab
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.7
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Style/AccessModifierDeclarations:
|
13
|
+
EnforcedStyle: inline
|
14
|
+
|
15
|
+
Naming/MethodParameterName:
|
16
|
+
MinNameLength: 1
|
17
|
+
|
18
|
+
Style/SymbolArray:
|
19
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ToProcInterface
|
2
2
|
|
3
|
-
The collection of mixins
|
3
|
+
The collection of mixins that makes your classes or instances act like a `Proc`. In the common way it handles some routines to memoize `#to_proc` method from a `#call` method object and delegates `Proc` instance methods to that proc.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,7 @@ gem install to_proc_interface
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
See docs.
|
22
22
|
|
23
23
|
## Development
|
24
24
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ToProcInterface
|
4
|
+
# The mixin to use when an instance-level {#call} method returns a monad.
|
5
|
+
module CallToMaybe
|
6
|
+
include ToProcInterface
|
7
|
+
|
8
|
+
# All the arguments passed to initializer.
|
9
|
+
# @see #initialize
|
10
|
+
# @see #call
|
11
|
+
# @return [Dry::Monad::Maybe]
|
12
|
+
def call(...)
|
13
|
+
new(...).call.to_maybe
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ToProcInterface
|
4
|
+
# @example Usage
|
5
|
+
# class Sum < Struct.new(:a, :b, keyword_init: true)
|
6
|
+
# extend ToProcInterface::CallingService
|
7
|
+
#
|
8
|
+
# def call
|
9
|
+
# self.a + self.b
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# [
|
14
|
+
# { a: 1, b: 2 },
|
15
|
+
# { a: 3, b: 4 }
|
16
|
+
# ].map(&Sum) # => [3, 7]
|
17
|
+
module CallingService
|
18
|
+
include ToProcInterface
|
19
|
+
|
20
|
+
# Initializes an object with the given args and invokes it's {#call} method without arguments.
|
21
|
+
# @see #initializer
|
22
|
+
# @see #call
|
23
|
+
def call(...)
|
24
|
+
new(...).call
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ToProcInterface
|
4
|
+
# The namespace for hook mixins & the composition mixin.
|
5
|
+
#
|
6
|
+
# @example Usage
|
7
|
+
# module MyToProcInterface
|
8
|
+
# include ToProcInterface::Mixin
|
9
|
+
# include ToProcInterface::Delegations
|
10
|
+
# extend ToProcInterface::Hooks
|
11
|
+
# end
|
12
|
+
module Hooks
|
13
|
+
# The mixin contains the {Class.inherited} hook for the proper memoization of {#to_proc} singleton class method.
|
14
|
+
# It is neccessary to use it when extending a singleton class with the interface.
|
15
|
+
# @api private
|
16
|
+
module Inherited
|
17
|
+
# @param subclass [Class]
|
18
|
+
# @return [void]
|
19
|
+
private def inherited(subclass)
|
20
|
+
if subclass.instance_variable_defined?(:@to_proc)
|
21
|
+
subclass.remove_instance_variable(:@to_proc)
|
22
|
+
subclass.to_proc
|
23
|
+
end
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# The mixin hooks the {#extend_object} method that selects
|
29
|
+
# the proper extension.
|
30
|
+
#
|
31
|
+
# @example Usage
|
32
|
+
# module Extension
|
33
|
+
# include ToProcInterface
|
34
|
+
# extend Hooks::Extended
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# class Example
|
38
|
+
# # @!parse extend ToProcInterface::Hooks::Inherited
|
39
|
+
# extend Extension
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# @api private
|
43
|
+
module Extended
|
44
|
+
# @return [void]
|
45
|
+
#
|
46
|
+
# @overload extend_object(module_object)
|
47
|
+
# @param module_object [Module]
|
48
|
+
# Extends the target module {ToProcInterface::Hooks::Included}.
|
49
|
+
#
|
50
|
+
# @overload extend_object(class_object)
|
51
|
+
# @param class_object [Class]
|
52
|
+
# Extends the target class with {ToProcInterface::Hooks::Inherited}
|
53
|
+
private def extend_object(object)
|
54
|
+
case object
|
55
|
+
when Class
|
56
|
+
object.extend Inherited
|
57
|
+
when Module
|
58
|
+
object.extend Included
|
59
|
+
end
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @example Usage
|
65
|
+
# module Mixin
|
66
|
+
# # @!parse extend ToProcInterface::Hooks::Included
|
67
|
+
# include ToProcInterface
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# class Example
|
71
|
+
# extend Mixin
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# @api private
|
75
|
+
module Included
|
76
|
+
# @return [void]
|
77
|
+
#
|
78
|
+
# @overload append_features(module_object)
|
79
|
+
# @param module_object [Module]
|
80
|
+
# Extends the target module (unless it is the namespaced {ToProcInterface::Singleton} mixin)
|
81
|
+
# with {Hooks::Extended}.
|
82
|
+
#
|
83
|
+
# @overload append_features(class_object)
|
84
|
+
# @param class_object [Class]
|
85
|
+
# Does nothing if includes to {Class}
|
86
|
+
private def append_features(base)
|
87
|
+
return false if base < self
|
88
|
+
|
89
|
+
case base
|
90
|
+
when Class
|
91
|
+
super
|
92
|
+
when Module
|
93
|
+
super
|
94
|
+
base.extend Extended unless ToProcInterface.const_defined?(:Singleton) && base == Singleton
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
include Extended
|
100
|
+
include Included
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ToProcInterface
|
4
|
+
# @example Usage
|
5
|
+
# class Sum < Struct.new(:a, :b, keyword_init: true)
|
6
|
+
# extend ToProcInterface::Initializer
|
7
|
+
# end
|
8
|
+
# [
|
9
|
+
# { a: 1, b: 2 },
|
10
|
+
# { a: 3, b: 4 }
|
11
|
+
# ].map(&Sum) # => [#<struct Sum a=1, b=2>, #<struct Sum a=3, b=4>]
|
12
|
+
module Initializer
|
13
|
+
include ToProcInterface
|
14
|
+
|
15
|
+
# Initializes an object with the given args and invokes it's {#call} method without arguments.
|
16
|
+
# @see #initializer
|
17
|
+
def call(...)
|
18
|
+
new(...)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ToProcInterface
|
4
|
+
# @example Usage
|
5
|
+
# class Sum < Struct.new(:a, :b, keyword_init: true)
|
6
|
+
# extend ToProcInterface::PerformingService
|
7
|
+
#
|
8
|
+
# def perform
|
9
|
+
# self.a + self.b
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# [
|
14
|
+
# { a: 1, b: 2 },
|
15
|
+
# { a: 3, b: 4 }
|
16
|
+
# ].map(&Sum) # => [3, 7]
|
17
|
+
module PerformingService
|
18
|
+
include ToProcInterface
|
19
|
+
|
20
|
+
# Initializes an object with the given args and invokes it's {#perform} method without arguments.
|
21
|
+
# @see #initializer
|
22
|
+
# @see #perform
|
23
|
+
def call(...)
|
24
|
+
new(...).perform
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
|
5
|
+
module ToProcInterface
|
6
|
+
# Singleton variation. {#to_proc} & {#call} delegated to {ToProcInterface::Singleton::ClassMethods.instance}
|
7
|
+
#
|
8
|
+
# @example Usage
|
9
|
+
# require "to_proc_interface/singleton"
|
10
|
+
#
|
11
|
+
# class Sum
|
12
|
+
# include ToProcInterface::Singleton
|
13
|
+
#
|
14
|
+
# def call(a, b)
|
15
|
+
# a + b
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Sum.(1, 2) # => 3
|
20
|
+
module Singleton
|
21
|
+
include ToProcInterface
|
22
|
+
|
23
|
+
# @api private
|
24
|
+
def self.included(base)
|
25
|
+
super
|
26
|
+
base.include ::Singleton
|
27
|
+
base.extend ClassMethods
|
28
|
+
end
|
29
|
+
|
30
|
+
# @api private
|
31
|
+
module ClassMethods
|
32
|
+
include Delegations
|
33
|
+
|
34
|
+
# @!attribute [r] instance
|
35
|
+
# @return [::Singleton]
|
36
|
+
|
37
|
+
# @return [Proc]
|
38
|
+
def to_proc
|
39
|
+
instance.to_proc
|
40
|
+
end
|
41
|
+
|
42
|
+
def call(...)
|
43
|
+
instance.call(...)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ToProcInterface
|
4
|
+
# @note
|
5
|
+
# Block passed to class-level {WrappingCall#call}
|
6
|
+
# will be yield to instance-level #call
|
7
|
+
module WrappingCall
|
8
|
+
include ToProcInterface
|
9
|
+
|
10
|
+
# @!scope class
|
11
|
+
|
12
|
+
def call(...)
|
13
|
+
if block_given?
|
14
|
+
call_safe(...)
|
15
|
+
else
|
16
|
+
call_unsafe(...)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def call_safe(*args, **opts, &block)
|
21
|
+
new(*args, **opts).call_safe(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def call_unsafe(...)
|
25
|
+
new(...).call_unsafe
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/to_proc_interface.rb
CHANGED
@@ -1,221 +1,126 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "to_proc_interface/hooks"
|
4
|
+
require "zeitwerk"
|
4
5
|
|
5
|
-
# @example
|
6
|
-
# class
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# @example Extended to a class
|
7
|
+
# class Sum
|
8
|
+
# extend ToProcInterface
|
9
|
+
#
|
10
|
+
# def self.call(a, b)
|
11
|
+
# a + b
|
9
12
|
# end
|
13
|
+
# end
|
10
14
|
#
|
11
|
-
#
|
15
|
+
# Sum[1, 2] # => 3
|
16
|
+
#
|
17
|
+
# @example Included to a class
|
18
|
+
# class Sum
|
19
|
+
# include ToProcInterface
|
20
|
+
#
|
21
|
+
# def call(a, b)
|
22
|
+
# a + b
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Sum.new[1, 2] # => 3
|
27
|
+
#
|
28
|
+
# @example Included to a module
|
29
|
+
# module YieldToInstanceCall
|
30
|
+
# # @!parse extend ToProcInterface::Hooks::Extended
|
31
|
+
# # @!parse extend ToProcInterface::Hooks::Inherited
|
32
|
+
# include ToProcInterface
|
33
|
+
#
|
34
|
+
# def call(*args, **opts, &block)
|
35
|
+
# new(*args, **opts).call(&block)
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# class BinaryOp
|
40
|
+
# extend YieldToInstanceCall
|
41
|
+
#
|
42
|
+
# def initialize(a, b)
|
43
|
+
# @a, @b = a, b
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# def call
|
47
|
+
# yield(@a, @b)
|
48
|
+
# end
|
12
49
|
# end
|
50
|
+
#
|
51
|
+
# BinaryOp.(1, 2, &:+) # => 3
|
13
52
|
module ToProcInterface
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
53
|
+
METHODS = [
|
54
|
+
:parameters,
|
55
|
+
:<<,
|
56
|
+
:yield,
|
57
|
+
:[],
|
58
|
+
:>>,
|
59
|
+
:arity,
|
60
|
+
:lambda?,
|
61
|
+
:binding,
|
62
|
+
:curry,
|
63
|
+
:source_location
|
64
|
+
].freeze
|
24
65
|
|
25
|
-
|
26
|
-
"",
|
27
|
-
"arg",
|
28
|
-
"*args, **opts, &block"
|
29
|
-
].freeze
|
30
|
-
|
31
|
-
# @!macro [new] delegate_to_proc
|
32
|
-
# @!method (...)
|
33
|
-
# @see Proc#
|
34
|
-
#
|
35
|
-
# @param name [Symbol, String]
|
36
|
-
# method name
|
37
|
-
# @param arity [Integer]
|
38
|
-
# method arity
|
39
|
-
# @return [Symbol]
|
40
|
-
# delegated method name
|
41
|
-
#
|
42
|
-
# @example Customize proc-delegated methods
|
43
|
-
# ToProcInterface::Delegations.delegate_to_proc :custom_proc_method, arity: 1
|
44
|
-
def delegate_to_proc(name, arity: nil)
|
45
|
-
name = name.to_sym
|
46
|
-
arity ||= Proc.instance_method(name).arity
|
47
|
-
args = @@args_by_arity[arity.clamp(-1, 1)]
|
48
|
-
|
49
|
-
class_eval(<<~RUBY, __FILE__, __LINE__ + 1).tap { proc_methods << _1 }
|
50
|
-
def #{name}(#{args})
|
51
|
-
to_proc.#{name}(#{args})
|
52
|
-
end
|
53
|
-
RUBY
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
delegate_to_proc :parameters, arity: 0
|
58
|
-
delegate_to_proc :arity, arity: 0
|
59
|
-
delegate_to_proc :lambda?, arity: 0
|
60
|
-
delegate_to_proc :binding, arity: 0
|
61
|
-
delegate_to_proc :curry, arity: -1
|
62
|
-
delegate_to_proc :yield, arity: -1
|
63
|
-
delegate_to_proc :[], arity: -1
|
64
|
-
delegate_to_proc :<<, arity: 1
|
65
|
-
delegate_to_proc :>>, arity: 1
|
66
|
-
delegate_to_proc :source_location
|
67
|
-
delegate_to_proc :ruby2_keywords if Proc.method_defined?(:ruby2_keywords)
|
68
|
-
end
|
69
|
-
|
70
|
-
# @api private
|
71
|
-
module Hooks
|
72
|
-
# @example Usage
|
73
|
-
# extend ToProcInterface::Hooks::Included
|
74
|
-
module Included
|
75
|
-
# @return [void]
|
76
|
-
private def included(base)
|
77
|
-
base.extend Extended if base.is_a?(Module) && !base.is_a?(Class)
|
78
|
-
super if defined?(super)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# @example Usage
|
83
|
-
# extend ToProcInterface::Hooks::Extended
|
84
|
-
module Extended
|
85
|
-
# Hooks an {Module#extended} callback method to mix in possible singleton class with {Inherited}.
|
86
|
-
# @return [void]
|
87
|
-
private def extended(base)
|
88
|
-
base.extend Inherited if base.is_a?(Class)
|
89
|
-
super if defined?(super)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# @example Usage
|
94
|
-
# extend ToProcInterface::Hooks::Inherited
|
95
|
-
module Inherited
|
96
|
-
# Hooks an {Class#inherited} method to avoid reusing cached {#to_proc} on inherited classes.
|
97
|
-
# @return [void]
|
98
|
-
private def inherited(subclass)
|
99
|
-
if subclass.instance_variable_defined?(:@to_proc)
|
100
|
-
subclass.remove_instance_variable(:@to_proc)
|
101
|
-
subclass.to_proc
|
102
|
-
end
|
103
|
-
super if defined?(super)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# @api private
|
66
|
+
# @abstract
|
109
67
|
module Mixin
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
# @return [Proc] built from the {#call} method
|
68
|
+
# @!attribute [r] to_proc
|
69
|
+
# @return [Proc] built from the {#call} method
|
114
70
|
def to_proc
|
115
71
|
@to_proc ||= method(:call).to_proc
|
116
72
|
end
|
117
|
-
end
|
118
|
-
|
119
|
-
include Mixin
|
120
|
-
|
121
|
-
# Interface with predefined {#call} method which delegates all the given params into class' constructor
|
122
|
-
# and invokes instance's {#call} method.
|
123
|
-
#
|
124
|
-
# @example Usage
|
125
|
-
# extend ToProcInterface::CallingService
|
126
|
-
module CallingService
|
127
|
-
include Mixin
|
128
|
-
|
129
|
-
# @see #initialize
|
130
|
-
# @see #call
|
131
|
-
def call(*args, **opts, &block)
|
132
|
-
instance = new(*args, **opts, &block)
|
133
|
-
instance.call
|
134
|
-
end
|
135
|
-
end
|
136
73
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
# @abstract
|
141
|
-
# The instance method `#call` should return a monad-like object responsible to `#to_maybe`.
|
142
|
-
#
|
143
|
-
# @example Usage
|
144
|
-
# extend ToProcInterface::CallToMaybe
|
145
|
-
module CallToMaybe
|
146
|
-
include Mixin
|
147
|
-
|
148
|
-
# @see #initialize
|
149
|
-
# @see #call
|
150
|
-
# @return [Dry::Monads::Maybe]
|
151
|
-
def call(*args, **opts, &block)
|
152
|
-
instance = new(*args, **opts, &block)
|
153
|
-
result = instance.call
|
154
|
-
result.to_maybe
|
74
|
+
# @abstract
|
75
|
+
def call
|
76
|
+
raise NotImplementedError
|
155
77
|
end
|
156
78
|
end
|
157
79
|
|
158
|
-
#
|
159
|
-
#
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
80
|
+
# The mixin brings all public methods of the {Proc} class to be delegated to the {Mixin#to_proc} method.
|
81
|
+
# @api private
|
82
|
+
module Delegations
|
83
|
+
template, *loc = <<~RUBY, __FILE__, __LINE__ + 1
|
84
|
+
# @see #to_proc
|
85
|
+
# @see Proc#%<name>s
|
86
|
+
def %<name>s(...)
|
87
|
+
to_proc.%<name>s(...)
|
88
|
+
end
|
89
|
+
RUBY
|
164
90
|
|
165
|
-
|
166
|
-
# @return [self]
|
167
|
-
def call(*args, **opts, &block)
|
168
|
-
new(*args, **opts, &block)
|
169
|
-
end
|
91
|
+
METHODS.each { module_eval(format(template, name: _1), *loc) }
|
170
92
|
end
|
171
93
|
|
172
|
-
|
173
|
-
|
174
|
-
#
|
175
|
-
# @example Usage
|
176
|
-
# extend ToProcInterface::PerformingService
|
177
|
-
module PerformingService
|
178
|
-
include Mixin
|
94
|
+
include Mixin
|
95
|
+
include Delegations
|
179
96
|
|
180
|
-
|
181
|
-
|
182
|
-
def call(*args, **opts, &block)
|
183
|
-
new(*args, **opts, &block).perform
|
184
|
-
end
|
185
|
-
end
|
97
|
+
# @!parse extend Hooks::Extended, Hooks::Included
|
98
|
+
extend Hooks
|
186
99
|
|
187
|
-
#
|
188
|
-
#
|
189
|
-
# @example Usage
|
190
|
-
# include ToProcInterface::Singleton
|
191
|
-
module Singleton
|
192
|
-
include ToProcInterface
|
100
|
+
# rubocop:disable Metrics/MethodLength
|
193
101
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
102
|
+
# @api private
|
103
|
+
def self.loader
|
104
|
+
@loader ||=
|
105
|
+
Zeitwerk::Loader.for_gem.tap do |loader|
|
106
|
+
root = __dir__
|
107
|
+
loader.tag = "to_proc_interface"
|
108
|
+
loader.push_dir root
|
109
|
+
loader.ignore \
|
110
|
+
"#{root}/to_proc_interface/call_to_maybe.rb",
|
111
|
+
"#{root}/to_proc_interface/hooks.rb",
|
112
|
+
"#{root}/to_proc_interface/performing_service.rb",
|
113
|
+
"#{root}/to_proc_interface/singleton.rb",
|
114
|
+
"#{root}/to_proc_interface/wrapping_call.rb"
|
115
|
+
|
116
|
+
if defined?(Pry)
|
117
|
+
loader.log!
|
118
|
+
loader.enable_reloading
|
200
119
|
end
|
201
|
-
super if defined?(super)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
# @private
|
206
|
-
module ClassMethods
|
207
|
-
# @see ToProcInterface#to_proc
|
208
|
-
# @return [Proc]
|
209
|
-
def to_proc
|
210
|
-
instance.to_proc
|
211
120
|
end
|
121
|
+
end
|
212
122
|
|
213
|
-
|
214
|
-
def call(*args, **opts, &block)
|
215
|
-
instance.call(*args, **opts, &block)
|
216
|
-
end
|
123
|
+
# rubocop:enable Metrics/MethodLength
|
217
124
|
|
218
|
-
|
219
|
-
|
220
|
-
end
|
221
|
-
end
|
125
|
+
loader.setup
|
126
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_proc_interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Anton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: zeitwerk
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
27
|
-
description: Collection of mixins
|
26
|
+
version: '0'
|
27
|
+
description: Collection of mixins that makes your classes & objects act like procs.
|
28
28
|
email:
|
29
29
|
- anton.estum@gmail.com
|
30
30
|
executables: []
|
@@ -32,21 +32,30 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- CHANGELOG.md
|
35
37
|
- CODE_OF_CONDUCT.md
|
36
38
|
- LICENSE.txt
|
37
39
|
- README.md
|
38
40
|
- Rakefile
|
39
41
|
- lib/to_proc_interface.rb
|
42
|
+
- lib/to_proc_interface/call_to_maybe.rb
|
43
|
+
- lib/to_proc_interface/calling_service.rb
|
44
|
+
- lib/to_proc_interface/hooks.rb
|
45
|
+
- lib/to_proc_interface/initializer.rb
|
46
|
+
- lib/to_proc_interface/performing_service.rb
|
47
|
+
- lib/to_proc_interface/singleton.rb
|
40
48
|
- lib/to_proc_interface/version.rb
|
41
|
-
-
|
49
|
+
- lib/to_proc_interface/wrapping_call.rb
|
42
50
|
homepage: https://github.com/estum/to_proc_interface
|
43
51
|
licenses:
|
44
52
|
- MIT
|
45
53
|
metadata:
|
46
54
|
allowed_push_host: https://rubygems.org
|
47
55
|
homepage_uri: https://github.com/estum/to_proc_interface
|
48
|
-
source_code_uri: https://github.com/estum/
|
49
|
-
changelog_uri: https://github.com/estum/
|
56
|
+
source_code_uri: https://github.com/estum/to_proc_interface
|
57
|
+
changelog_uri: https://github.com/estum/to_proc_interface/blob/main/CHANGELOG.md
|
58
|
+
rubygems_mfa_required: 'true'
|
50
59
|
post_install_message:
|
51
60
|
rdoc_options: []
|
52
61
|
require_paths:
|
@@ -62,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
71
|
- !ruby/object:Gem::Version
|
63
72
|
version: '0'
|
64
73
|
requirements: []
|
65
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.1.6
|
66
75
|
signing_key:
|
67
76
|
specification_version: 4
|
68
|
-
summary:
|
77
|
+
summary: Collection of mixins that makes your classes & objects act like procs.
|
69
78
|
test_files: []
|