debounced 0.1.21 → 1.0.1.draft

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: '08e33800aa43c78d6be5abffcda05d1ca70e46436531f42f79193cbf1ab86059'
4
- data.tar.gz: 455c57c30a34f260aeb6adf2e61c45c13b190d13b8e4236f324f6a703beab655
3
+ metadata.gz: d86d225d48355f7711c357ed64f7e7ef6f0bba3914f4b20a2e31676b3268596e
4
+ data.tar.gz: b696398beda978e412a2f02d733b997055a5da7952044a64ff83ea0462f53fd3
5
5
  SHA512:
6
- metadata.gz: 32a872b4f22b473ec19890db74d264a11931fc810c57d83f9d14e1ce1ff18f4eb2f5403b74d45feb16fdf27cd236886e19ba18f9096d6009bcc0a6aed574ce93
7
- data.tar.gz: fabd72e50c1b94cbb4fcf2677306c360f8eb299e9eff14b7acb380b1737722e54e2ee5ec03ea58d76cdb82427cc5dca0b36542367748a30833ec288d3c553be8
6
+ metadata.gz: 6be16ccac02c0426416e1211a4cb2603b20cfc171eb81f15419f50b9db44d3b783de9f2e3a9a05670919da47505fd292b9637bf7a70513c9878b3a02f6d08372
7
+ data.tar.gz: 67b9908e4fe87f550a2c75b8f6a045fbaf3f1a3b6be36dabfeaf096388bff1750f69f356ce74a9128b2d8bad548333323a0dd60588594a2e815cfb235285a45e
@@ -1,53 +1,52 @@
1
- require 'debug'
2
-
3
1
  module Debounced
4
- class Callback
5
2
 
6
- attr_accessor :class_name, :params, :method_name, :method_params
3
+ ###
4
+ # Represents a callback to be executed by the debounce service
5
+ class Callback
6
+ attr_accessor :class_name, :method_name, :args, :kwargs
7
7
 
8
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
18
- def initialize(class_name:, params:, method_name:, method_params:)
9
+ # @param [String] class_name the name of the class that will receive the callback
10
+ # @param [String] method_name the name of the method that will be called
11
+ # @param [Array] args the positional arguments to be passed to the method (optional)
12
+ # @param [Hash] kwargs the keyword arguments to be passed to the method (optional)
13
+ #
14
+ # @note if the class implements the method_name, the message will be sent to the class with the args and kwargs.
15
+ # otherwise, an instance of the class will be created and the message will be sent to the instance. in this case,
16
+ # the args and kwargs will be passed to the initializer.
17
+ def initialize(class_name:, method_name:, args: [], kwargs: {})
19
18
  @class_name = class_name.to_s
20
- @params = params || {}
21
19
  @method_name = method_name.to_s
22
- @method_params = method_params || []
20
+ @args = args
21
+ @kwargs = kwargs
23
22
  end
24
23
 
25
24
  def self.parse(data)
26
25
  new(
27
26
  class_name: data['class_name'],
28
- params: data['params'],
29
27
  method_name: data['method_name'],
30
- method_params: data['method_params']
28
+ args: data['args'],
29
+ kwargs: data['kwargs'].transform_keys(&:to_sym),
31
30
  )
32
31
  end
33
32
 
34
33
  def as_json
35
34
  {
36
35
  class_name:,
37
- params:,
38
36
  method_name:,
39
- method_params:
37
+ args:,
38
+ kwargs:,
40
39
  }
41
40
  end
42
41
 
43
42
  def call
44
43
  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))
44
+ if klass.respond_to?(method_name)
45
+ klass.send(method_name, *args, **kwargs)
46
+ else
47
+ instance = klass.new(*args, **kwargs)
48
+ instance.send(method_name)
49
49
  end
50
- target.send(message, *method_params)
51
50
  end
52
51
 
53
52
  end
@@ -1,7 +1,5 @@
1
1
  require 'socket'
2
2
  require 'json'
3
- require 'json/add/core'
4
- require 'debug'
5
3
 
6
4
  module Debounced
7
5
  ###
@@ -1,3 +1,3 @@
1
1
  module Debounced
2
- VERSION = "0.1.21"
2
+ VERSION = "1.0.1.draft"
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.21
4
+ version: 1.0.1.draft
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Passero