diff options
author | David Heinemeier Hansson <david@basecamp.com> | 2014-06-12 12:20:39 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@basecamp.com> | 2014-06-12 12:20:39 +0200 |
commit | 4ac8dc21440ecdea9c0452a0c12e8bcc487bc776 (patch) | |
tree | 23c7450738ada9a47fb1ecb61d425d046950240b | |
parent | 4eae97a5cf3954ff1422de08a1120f7b205be9ba (diff) | |
parent | c0f5b7346da26908d47021d473a2f590939d7ba0 (diff) | |
download | rails-4ac8dc21440ecdea9c0452a0c12e8bcc487bc776.tar.gz rails-4ac8dc21440ecdea9c0452a0c12e8bcc487bc776.tar.bz2 rails-4ac8dc21440ecdea9c0452a0c12e8bcc487bc776.zip |
Merge pull request #83 from DouweM/patch-8
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 |