aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_job/arguments.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2014-05-22 19:35:45 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2014-05-22 19:35:45 +0200
commit387a7d993573b1492b1ed39f6803acc77af9233b (patch)
tree611ccdb86508a8d190fbac2efb3aa7ea5e5a67b1 /lib/active_job/arguments.rb
parentc073ba339a6820625718f7320989cfa527534563 (diff)
downloadrails-387a7d993573b1492b1ed39f6803acc77af9233b.tar.gz
rails-387a7d993573b1492b1ed39f6803acc77af9233b.tar.bz2
rails-387a7d993573b1492b1ed39f6803acc77af9233b.zip
Standardize on "arguments" for everything -- no more "paramters"
Diffstat (limited to 'lib/active_job/arguments.rb')
-rw-r--r--lib/active_job/arguments.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/active_job/arguments.rb b/lib/active_job/arguments.rb
new file mode 100644
index 0000000000..d1cc6d3177
--- /dev/null
+++ b/lib/active_job/arguments.rb
@@ -0,0 +1,24 @@
+require 'active_model/global_locator'
+require 'active_support/core_ext/object/try'
+
+module ActiveJob
+ class Arguments
+ TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Hash, Array, Bignum ]
+
+ def self.serialize(arguments)
+ arguments.collect do |argument|
+ if argument.respond_to?(:global_id)
+ argument.global_id
+ elsif TYPE_WHITELIST.include?(argument.class)
+ argument
+ else
+ raise "Unsupported argument type: #{argument.class.name}"
+ end
+ end
+ end
+
+ def self.deserialize(arguments)
+ arguments.collect { |argument| ActiveModel::GlobalLocator.locate(argument) || argument }
+ end
+ end
+end