inst-jobs 0.11.8 → 0.11.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f024416c8aac90611b46a38491ebc35373bc2136
4
- data.tar.gz: f729a0faea215acb32cc8e9d7fbd07b05f96ba9d
3
+ metadata.gz: 6fc1b53dbd69b8847b9a87b9605899225659e6bd
4
+ data.tar.gz: 05ff57cb08b532ddadb1cf82f0490820847ad466
5
5
  SHA512:
6
- metadata.gz: 00e97f21ed4245ee6452ce553b82e8c50e62d92e70a47515d5dfed0c2d7ec4d0a76a910b8c757eaa62d00e5cd6d79e55dfa570b748156ba9fdb50e5428055847
7
- data.tar.gz: c09a528aeb3c0a055e0e54b6692e76e418636b170af3484467f5d451d84fcd8fa867c7a1da187b9dcab9b662984fe656444fb28d8a4ec21b3a329d75fadb927e
6
+ metadata.gz: a96b91c87fc000b003523e61cabe07ef7d433a7054423c9c50ecb96338a0e96c53d3de4589d6cb5baab91af2b81a6a2b8e9fca421f83bcd1b41cebde2a7cae6b
7
+ data.tar.gz: 0ed8814fa280e81da6e7d0632f91be46aaa4f09a34d9bfe715af0fd7f4b191433e59bf87400c2956f51d23dcceda3a59b83c13532bfd63f02e0d8e01c53be220
@@ -95,35 +95,54 @@ module Delayed
95
95
  end
96
96
 
97
97
  module ClassMethods
98
- def add_send_later_methods(method, enqueue_args={}, default_async=false)
99
- aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
98
+ KWARG_ARG_TYPES = %i{key keyreq keyrest}.freeze
99
+ private_constant :KWARG_ARG_TYPES
100
+
101
+ def add_send_later_methods(method_name, enqueue_args={}, default_async=false)
102
+ aliased_method, punctuation = method_name.to_s.sub(/([?!=])$/, ''), $1
100
103
 
101
104
  # we still need this for backwards compatibility
102
105
  without_method = "#{aliased_method}_without_send_later#{punctuation}"
103
106
 
104
- if public_method_defined?(method)
107
+ if public_method_defined?(method_name)
105
108
  visibility = :public
106
- elsif private_method_defined?(method)
109
+ elsif private_method_defined?(method_name)
107
110
  visibility = :private
108
111
  else
109
112
  visibility = :protected
110
113
  end
111
114
 
112
- generated_delayed_methods.class_eval do
113
- define_method without_method do |*args|
114
- send(method, *args, synchronous: true)
115
- end
116
- send(visibility, without_method)
115
+ if has_kwargs? method_name
116
+ generated_delayed_methods.class_eval do
117
+ define_method without_method do |*args, **kwargs|
118
+ send(method_name, *args, synchronous: true, **kwargs)
119
+ end
117
120
 
118
- define_method(method, -> (*args, synchronous: !default_async) do
119
- if synchronous
120
- super(*args)
121
- else
122
- send_later_enqueue_args(method, enqueue_args, *args, synchronous: true)
121
+ define_method(method_name, -> (*args, synchronous: !default_async, **kwargs) do
122
+ if synchronous
123
+ super(*args, **kwargs)
124
+ else
125
+ send_later_enqueue_args(method_name, enqueue_args, *args, synchronous: true, **kwargs)
126
+ end
127
+ end)
128
+ end
129
+ else
130
+ generated_delayed_methods.class_eval do
131
+ define_method without_method do |*args|
132
+ send(method_name, *args, synchronous: true)
123
133
  end
124
- end)
125
- send(visibility, method)
134
+
135
+ define_method(method_name, -> (*args, synchronous: !default_async) do
136
+ if synchronous
137
+ super(*args)
138
+ else
139
+ send_later_enqueue_args(method_name, enqueue_args, *args, synchronous: true)
140
+ end
141
+ end)
142
+ end
126
143
  end
144
+ generated_delayed_methods.send(visibility, without_method)
145
+ generated_delayed_methods.send(visibility, method_name)
127
146
  end
128
147
 
129
148
  def handle_asynchronously(method, enqueue_args={})
@@ -138,12 +157,19 @@ module Delayed
138
157
  add_send_later_methods(method, enqueue_args, Rails.env.production?)
139
158
  end
140
159
 
141
- private def generated_delayed_methods
160
+ private
161
+
162
+ def generated_delayed_methods
142
163
  @generated_delayed_methods ||= Module.new.tap do |mod|
143
164
  const_set(:DelayedMethods, mod)
144
165
  prepend mod
145
166
  end
146
167
  end
168
+
169
+ def has_kwargs?(method_name)
170
+ original_arg_types = instance_method(method_name).parameters.map(&:first)
171
+ original_arg_types.any? { |arg_type| KWARG_ARG_TYPES.include?(arg_type) }
172
+ end
147
173
  end
148
174
  end
149
175
  end
@@ -1,3 +1,3 @@
1
1
  module Delayed
2
- VERSION = "0.11.8"
2
+ VERSION = "0.11.9"
3
3
  end
@@ -56,6 +56,21 @@ shared_examples_for 'random ruby objects' do
56
56
  lambda { obj.test_method }.should change { Delayed::Job.jobs_count(:current) }.by(1)
57
57
  end
58
58
 
59
+ it 'must work with kwargs in the original method' do
60
+ klass = Class.new do
61
+ attr_reader :run
62
+ def test_method(my_kwarg: nil); @run = my_kwarg; end
63
+ add_send_later_methods :test_method
64
+
65
+ def other_test(arg); @foo = arg; end
66
+ add_send_later_methods :other_test
67
+ end
68
+
69
+ obj = klass.new
70
+ obj.test_method(my_kwarg: 'foo', synchronous: true)
71
+ expect(obj.run).to eq 'foo'
72
+ end
73
+
59
74
  it "should work without default_async" do
60
75
  klass = Class.new do
61
76
  attr_accessor :ran
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.8
4
+ version: 0.11.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-19 00:00:00.000000000 Z
12
+ date: 2017-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: after_transaction_commit