aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json/encoders.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/json/encoders.rb')
-rw-r--r--activesupport/lib/active_support/json/encoders.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/json/encoders.rb b/activesupport/lib/active_support/json/encoders.rb
new file mode 100644
index 0000000000..c3e3619f59
--- /dev/null
+++ b/activesupport/lib/active_support/json/encoders.rb
@@ -0,0 +1,25 @@
+module ActiveSupport
+ module JSON #:nodoc:
+ module Encoders
+ mattr_accessor :encoders
+ @@encoders = {}
+
+ class << self
+ def define_encoder(klass, &block)
+ encoders[klass] = block
+ end
+
+ def [](klass)
+ klass.ancestors.each do |k|
+ encoder = encoders[k]
+ return encoder if encoder
+ end
+ end
+ end
+ end
+ end
+end
+
+Dir[File.dirname(__FILE__) + '/encoders/*.rb'].each do |file|
+ require file[0..-4]
+end