debounced 0.1.20 → 0.1.21
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 +21 -5
- data/lib/debounced/service_proxy.rb +1 -1
- 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: '08e33800aa43c78d6be5abffcda05d1ca70e46436531f42f79193cbf1ab86059'
|
4
|
+
data.tar.gz: 455c57c30a34f260aeb6adf2e61c45c13b190d13b8e4236f324f6a703beab655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32a872b4f22b473ec19890db74d264a11931fc810c57d83f9d14e1ce1ff18f4eb2f5403b74d45feb16fdf27cd236886e19ba18f9096d6009bcc0a6aed574ce93
|
7
|
+
data.tar.gz: fabd72e50c1b94cbb4fcf2677306c360f8eb299e9eff14b7acb380b1737722e54e2ee5ec03ea58d76cdb82427cc5dca0b36542367748a30833ec288d3c553be8
|
data/lib/debounced/callback.rb
CHANGED
@@ -3,7 +3,18 @@ require 'debug'
|
|
3
3
|
module Debounced
|
4
4
|
class Callback
|
5
5
|
|
6
|
-
|
6
|
+
attr_accessor :class_name, :params, :method_name, :method_params
|
7
|
+
|
8
|
+
###
|
9
|
+
# Create a new callback object
|
10
|
+
# @param class_name [String] the name of the class to call the method on
|
11
|
+
# @param params [Hash] a hash of parameters to pass to the class initializer (optional)
|
12
|
+
# @param method_name [String] the name of the method to call.
|
13
|
+
# If the method is a class method, it should be prefixed with a "."
|
14
|
+
# If it is an instance method, it should be prefixed with a "#"
|
15
|
+
# @param method_params [Array] an array of parameters to pass to the method
|
16
|
+
# @return [Debounced::Callback]
|
17
|
+
# @note @params is ignored if the method is a class method
|
7
18
|
def initialize(class_name:, params:, method_name:, method_params:)
|
8
19
|
@class_name = class_name.to_s
|
9
20
|
@params = params || {}
|
@@ -11,7 +22,7 @@ module Debounced
|
|
11
22
|
@method_params = method_params || []
|
12
23
|
end
|
13
24
|
|
14
|
-
def self.
|
25
|
+
def self.parse(data)
|
15
26
|
new(
|
16
27
|
class_name: data['class_name'],
|
17
28
|
params: data['params'],
|
@@ -30,9 +41,14 @@ module Debounced
|
|
30
41
|
end
|
31
42
|
|
32
43
|
def call
|
33
|
-
Object.const_get(class_name)
|
34
|
-
|
35
|
-
|
44
|
+
klass = Object.const_get(class_name)
|
45
|
+
message = method_name[1..-1] # strip of method_name prefix, either "." or "#"
|
46
|
+
target = klass
|
47
|
+
if method_name[0] == '#'
|
48
|
+
target = klass.new(**params.transform_keys(&:to_sym))
|
49
|
+
end
|
50
|
+
target.send(message, *method_params)
|
36
51
|
end
|
52
|
+
|
37
53
|
end
|
38
54
|
end
|
data/lib/debounced/version.rb
CHANGED