debounced 0.1.21 → 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 +4 -4
- data/lib/debounced/callback.rb +24 -23
- data/lib/debounced/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9fa31f8c531515f56ebb9c17aac23f5d21dab01efd0873daad72a54cf34dd6a
|
4
|
+
data.tar.gz: 89fb0e0a4d6a0be2dcf116d428b4f43673dc9e2509d58f6ce4f43036a9d8219d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15046d6c59bcddb75356cfa5ee60b96a26ce39dbbc9e269e9cb1a0ae8d50185bb21e9f1ba45afc938fba4df791718e113d9e9bd9342d3b5b2bc234d8c821af6c
|
7
|
+
data.tar.gz: fce8f73888019549fa9f4ccb642b20b5596ab0ba587bc7218c403907d2e99f1268965e7af1bc72a0993040a91777e35bd4df6dbd6e5cc7163160d75ad6de9b09
|
data/lib/debounced/callback.rb
CHANGED
@@ -1,53 +1,54 @@
|
|
1
1
|
require 'debug'
|
2
2
|
|
3
3
|
module Debounced
|
4
|
-
class Callback
|
5
4
|
|
6
|
-
|
5
|
+
###
|
6
|
+
# Represents a callback to be executed by the debounce service
|
7
|
+
class Callback
|
8
|
+
attr_accessor :class_name, :method_name, :args, :kwargs
|
7
9
|
|
8
10
|
###
|
9
|
-
#
|
10
|
-
# @param
|
11
|
-
# @param
|
12
|
-
# @param
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
def initialize(class_name:, params:, method_name:, method_params:)
|
11
|
+
# @param [String] class_name the name of the class that will receive the callback
|
12
|
+
# @param [String] method_name the name of the method that will be called
|
13
|
+
# @param [Array] args the positional arguments to be passed to the method (optional)
|
14
|
+
# @param [Hash] kwargs the keyword arguments to be passed to the method (optional)
|
15
|
+
#
|
16
|
+
# @note if the class implements the method_name, the message will be sent to the class with the args and kwargs.
|
17
|
+
# otherwise, an instance of the class will be created and the message will be sent to the instance. in this case,
|
18
|
+
# the args and kwargs will be passed to the initializer.
|
19
|
+
def initialize(class_name:, method_name:, args: [], kwargs: {})
|
19
20
|
@class_name = class_name.to_s
|
20
|
-
@params = params || {}
|
21
21
|
@method_name = method_name.to_s
|
22
|
-
@
|
22
|
+
@args = args
|
23
|
+
@kwargs = kwargs
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.parse(data)
|
26
27
|
new(
|
27
28
|
class_name: data['class_name'],
|
28
|
-
params: data['params'],
|
29
29
|
method_name: data['method_name'],
|
30
|
-
|
30
|
+
args: data['args'],
|
31
|
+
kwargs: data['kwargs'].transform_keys(&:to_sym),
|
31
32
|
)
|
32
33
|
end
|
33
34
|
|
34
35
|
def as_json
|
35
36
|
{
|
36
37
|
class_name:,
|
37
|
-
params:,
|
38
38
|
method_name:,
|
39
|
-
|
39
|
+
args:,
|
40
|
+
kwargs:,
|
40
41
|
}
|
41
42
|
end
|
42
43
|
|
43
44
|
def call
|
44
45
|
klass = Object.const_get(class_name)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
if klass.respond_to?(method_name)
|
47
|
+
klass.send(method_name, *args, **kwargs)
|
48
|
+
else
|
49
|
+
instance = klass.new(*args, **kwargs)
|
50
|
+
instance.send(method_name)
|
49
51
|
end
|
50
|
-
target.send(message, *method_params)
|
51
52
|
end
|
52
53
|
|
53
54
|
end
|
data/lib/debounced/version.rb
CHANGED