From c0f5b7346da26908d47021d473a2f590939d7ba0 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 5 Jun 2014 22:10:41 +0200 Subject: Clean up Arguments somewhat --- lib/active_job/arguments.rb | 23 +++++++++++++---------- 1 file 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 -- cgit v1.2.3