methods 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/methods.rb +16 -0
- data/lib/methods/configuration.rb +13 -0
- data/lib/methods/method_without_args.rb +1 -1
- data/lib/methods/methods_wrapper.rb +16 -3
- data/lib/methods/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dd71ba999826af79057611a774dff493bb94f29534eada9397e29da7331166b1
|
4
|
+
data.tar.gz: 65581fa0b8848b749fb9812fa6ae343c55ca1f232efb2cc307ef0cc89741f943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 447de97c4769ffd90c93dc1a6a0ce69a001aabcd19e986069011d072e7ed304237fab129c1053ae74cdc08da03e6537054ef588c259cf2cc7498ba89a68615ce
|
7
|
+
data.tar.gz: 844691c88d6a18de6e0af2bd6785aebac1ceac993cb22b8b004eda9ba42b6011651665c3ee8e92ff3a0fccb7a3ca9a5ae5c8b02311e5d49aa2ed90a926782134
|
data/lib/methods.rb
CHANGED
@@ -1,10 +1,26 @@
|
|
1
1
|
require "methods/version"
|
2
|
+
require "methods/configuration"
|
2
3
|
require 'binding_of_caller'
|
3
4
|
require "methods/methods_wrapper"
|
4
5
|
require "methods/instance_methods_wrapper"
|
5
6
|
require "methods/method_without_args"
|
6
7
|
|
7
8
|
module Methods
|
9
|
+
class << self
|
10
|
+
attr_accessor :configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.reset
|
18
|
+
@configuration = Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configure
|
22
|
+
yield(configuration)
|
23
|
+
end
|
8
24
|
end
|
9
25
|
|
10
26
|
Object.include Methods::MethodWithoutArgs
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Methods
|
2
|
+
class Configuration
|
3
|
+
# Defines if the curried args are prepended or appended to the
|
4
|
+
# arguments received during the method call
|
5
|
+
#
|
6
|
+
# Valid values: :prepend, :append
|
7
|
+
attr_accessor :curry_args_strategy
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@curry_args_strategy = :prepend
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Methods
|
2
2
|
class MethodsWrapper < BasicObject
|
3
|
-
def initialize(obj)
|
3
|
+
def initialize(obj, configuration)
|
4
4
|
@obj = obj
|
5
|
+
@configuration = configuration
|
5
6
|
end
|
6
7
|
|
7
8
|
def method_missing(method, *args, **kwargs, &block)
|
@@ -12,12 +13,13 @@ module Methods
|
|
12
13
|
method
|
13
14
|
else
|
14
15
|
::Kernel.lambda do |*call_args, **call_kwargs, &call_block|
|
16
|
+
merged_args = __methods_merge_args(args, call_args)
|
15
17
|
merged_kwargs = kwargs.merge(**call_kwargs)
|
16
18
|
merged_block = call_block || block
|
17
19
|
if merged_kwargs.empty?
|
18
|
-
method.call(*
|
20
|
+
method.call(*merged_args, &merged_block)
|
19
21
|
else
|
20
|
-
method.call(*
|
22
|
+
method.call(*merged_args, **merged_kwargs, &merged_block)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -37,6 +39,17 @@ module Methods
|
|
37
39
|
|
38
40
|
private
|
39
41
|
|
42
|
+
def __methods_merge_args(args, call_args)
|
43
|
+
case @configuration.curry_args_strategy
|
44
|
+
when :prepend then [*args, *call_args]
|
45
|
+
when :append then [*call_args, *args]
|
46
|
+
else
|
47
|
+
warn "Invalid value for option curry_args_strategy = #{@configuration.curry_args_strategy.inspect}"
|
48
|
+
warn "Falling back to :prepend"
|
49
|
+
[*args, *call_args]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
40
53
|
def __raise_no_method_error(method)
|
41
54
|
::Kernel.raise ::NoMethodError, "undefined method '#{method}' for #{@obj.inspect}:#{@obj.class.name}"
|
42
55
|
end
|
data/lib/methods/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Roszczyk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- bin/console
|
85
85
|
- bin/setup
|
86
86
|
- lib/methods.rb
|
87
|
+
- lib/methods/configuration.rb
|
87
88
|
- lib/methods/instance_methods_wrapper.rb
|
88
89
|
- lib/methods/method_without_args.rb
|
89
90
|
- lib/methods/methods_wrapper.rb
|
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
version: '0'
|
111
112
|
requirements: []
|
112
113
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.7.3
|
114
115
|
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: making referencing methods in Ruby easy
|