diff options
author | Douwe Maan <douwe@selenight.nl> | 2014-06-05 22:10:41 +0200 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2014-06-05 22:10:41 +0200 |
commit | c0f5b7346da26908d47021d473a2f590939d7ba0 (patch) | |
tree | 2bd2aecc566b5f64334544594d2521a4f6572a59 | |
parent | 694b562080a7b1473d20c743877481e13d51c421 (diff) | |
download | rails-c0f5b7346da26908d47021d473a2f590939d7ba0.tar.gz rails-c0f5b7346da26908d47021d473a2f590939d7ba0.tar.bz2 rails-c0f5b7346da26908d47021d473a2f590939d7ba0.zip |
Clean up Arguments somewhat
-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 |