diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_job/arguments.rb | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/active_job/arguments.rb b/lib/active_job/arguments.rb index 553ab20f65..604c3bfe1d 100644 --- a/lib/active_job/arguments.rb +++ b/lib/active_job/arguments.rb @@ -1,41 +1,44 @@ require 'active_model/global_locator' -require 'active_support/core_ext/object/try' module ActiveJob class Arguments TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ] def self.serialize(arguments) - arguments.collect do |argument| + arguments.map { |argument| serialize_argument(argument) } + end + + def self.deserialize(arguments) + arguments.map { |argument| deserialize_argument(argument) } + end + + private + def self.serialize_argument(argument) case argument when ActiveModel::GlobalIdentification argument.global_id when *TYPE_WHITELIST argument - when Hash - Hash[ argument.map{ |key, value| [ serialize_hash_key(key), serialize([value]).first ] } ] when Array serialize(argument) + when Hash + Hash[ argument.map { |key, value| [ serialize_hash_key(key), serialize_argument(value) ] } ] else raise "Unsupported argument type: #{argument.class.name}" end end - end - def self.deserialize(arguments) - arguments.collect do |argument| + def self.deserialize_argument(argument) case argument when Array deserialize(argument) when Hash - Hash[argument.map{ |key, value| [ key, deserialize([value]).first ] }].with_indifferent_access + Hash[ argument.map { |key, value| [ key, deserialize_argument(value) ] } ].with_indifferent_access else ActiveModel::GlobalLocator.locate(argument) || argument end end - end - private def self.serialize_hash_key(key) case key when String, Symbol |