101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/delayed/message_sending.rb', line 101
def add_send_later_methods(method_name, enqueue_args={}, default_async=false)
aliased_method, punctuation = method_name.to_s.sub(/([?!=])$/, ''), $1
without_method = "#{aliased_method}_without_send_later#{punctuation}"
if public_method_defined?(method_name)
visibility = :public
elsif private_method_defined?(method_name)
visibility = :private
else
visibility = :protected
end
if has_kwargs? method_name
generated_delayed_methods.class_eval do
define_method without_method do |*args, **kwargs|
send(method_name, *args, synchronous: true, **kwargs)
end
define_method(method_name, -> (*args, synchronous: !default_async, **kwargs) do
if synchronous
super(*args, **kwargs)
else
send_later_enqueue_args(method_name, enqueue_args, *args, synchronous: true, **kwargs)
end
end)
end
else
generated_delayed_methods.class_eval do
define_method without_method do |*args|
send(method_name, *args, synchronous: true)
end
define_method(method_name, -> (*args, synchronous: !default_async) do
if synchronous
super(*args)
else
send_later_enqueue_args(method_name, enqueue_args, *args, synchronous: true)
end
end)
end
end
generated_delayed_methods.send(visibility, without_method)
generated_delayed_methods.send(visibility, method_name)
end
|