debounced 0.1.20 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0b2a5d98cbf80bf222866ad69db51d71b000ea1e13a7bf16d7ddc638aa91923
4
- data.tar.gz: f031cae66cd65f40da805111ac8b31140de3e901f19f742bffe1ab593627bb27
3
+ metadata.gz: e9fa31f8c531515f56ebb9c17aac23f5d21dab01efd0873daad72a54cf34dd6a
4
+ data.tar.gz: 89fb0e0a4d6a0be2dcf116d428b4f43673dc9e2509d58f6ce4f43036a9d8219d
5
5
  SHA512:
6
- metadata.gz: d498b7e15fb3aef46c5789d1df43d143970daf40a48bd9f71d5f0664330cda646d9d6d36e8936a334acefdb62d40c3e966ccff7b5fcfeaabf2ea47cf41edada9
7
- data.tar.gz: 05ec409dbede721aab6457c29b564a8d8565d87208b3816ec37f1e8a4e3aa2049a4f663e8612e3969ab4e0023058e52f14351529f27f6e8eb710969d9be7b130
6
+ metadata.gz: 15046d6c59bcddb75356cfa5ee60b96a26ce39dbbc9e269e9cb1a0ae8d50185bb21e9f1ba45afc938fba4df791718e113d9e9bd9342d3b5b2bc234d8c821af6c
7
+ data.tar.gz: fce8f73888019549fa9f4ccb642b20b5596ab0ba587bc7218c403907d2e99f1268965e7af1bc72a0993040a91777e35bd4df6dbd6e5cc7163160d75ad6de9b09
@@ -1,38 +1,55 @@
1
1
  require 'debug'
2
2
 
3
3
  module Debounced
4
+
5
+ ###
6
+ # Represents a callback to be executed by the debounce service
4
7
  class Callback
8
+ attr_accessor :class_name, :method_name, :args, :kwargs
5
9
 
6
- attr_reader :class_name, :params, :method_name, :method_params
7
- def initialize(class_name:, params:, method_name:, method_params:)
10
+ ###
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: {})
8
20
  @class_name = class_name.to_s
9
- @params = params || {}
10
21
  @method_name = method_name.to_s
11
- @method_params = method_params || []
22
+ @args = args
23
+ @kwargs = kwargs
12
24
  end
13
25
 
14
- def self.json_create(data)
26
+ def self.parse(data)
15
27
  new(
16
28
  class_name: data['class_name'],
17
- params: data['params'],
18
29
  method_name: data['method_name'],
19
- method_params: data['method_params']
30
+ args: data['args'],
31
+ kwargs: data['kwargs'].transform_keys(&:to_sym),
20
32
  )
21
33
  end
22
34
 
23
35
  def as_json
24
36
  {
25
37
  class_name:,
26
- params:,
27
38
  method_name:,
28
- method_params:
39
+ args:,
40
+ kwargs:,
29
41
  }
30
42
  end
31
43
 
32
44
  def call
33
- Object.const_get(class_name)
34
- .new(**params.transform_keys(&:to_sym))
35
- .send(method_name, *method_params)
45
+ klass = Object.const_get(class_name)
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)
51
+ end
36
52
  end
53
+
37
54
  end
38
55
  end
@@ -116,7 +116,7 @@ module Debounced
116
116
  end
117
117
 
118
118
  def instantiate_callback(data)
119
- Callback.json_create(data)
119
+ Callback.parse(data)
120
120
  end
121
121
 
122
122
  def socket_descriptor
@@ -1,3 +1,3 @@
1
1
  module Debounced
2
- VERSION = "0.1.20"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debounced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Passero