summaryrefslogtreecommitdiff
path: root/trunk/ext/json/lib/json/add
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/ext/json/lib/json/add')
-rw-r--r--trunk/ext/json/lib/json/add/core.rb120
-rw-r--r--trunk/ext/json/lib/json/add/rails.rb58
2 files changed, 0 insertions, 178 deletions
diff --git a/trunk/ext/json/lib/json/add/core.rb b/trunk/ext/json/lib/json/add/core.rb
deleted file mode 100644
index 630ed6e4b7..0000000000
--- a/trunk/ext/json/lib/json/add/core.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-# This file contains implementations of ruby core's custom objects for
-# serialisation/deserialisation.
-
-unless Object.const_defined?(:JSON) and ::JSON.const_defined?(:JSON_LOADED) and
- ::JSON::JSON_LOADED
- require 'json'
-end
-require 'date'
-
-class Time
- def self.json_create(object)
- at(*object.values_at('s', 'u'))
- end
-
- def to_json(*args)
- {
- 'json_class' => self.class.name.to_s,
- 's' => tv_sec,
- 'u' => tv_usec,
- }.to_json(*args)
- end
-end
-
-class Date
- def self.json_create(object)
- civil(*object.values_at('y', 'm', 'd', 'sg'))
- end
-
- def to_json(*args)
- {
- 'json_class' => self.class.name.to_s,
- 'y' => year,
- 'm' => month,
- 'd' => day,
- 'sg' => @sg,
- }.to_json(*args)
- end
-end
-
-class DateTime
- def self.json_create(object)
- args = object.values_at('y', 'm', 'd', 'H', 'M', 'S')
- of_a, of_b = object['of'].split('/')
- args << Rational(of_a.to_i, of_b.to_i)
- args << object['sg']
- civil(*args)
- end
-
- def to_json(*args)
- {
- 'json_class' => self.class.name.to_s,
- 'y' => year,
- 'm' => month,
- 'd' => day,
- 'H' => hour,
- 'M' => min,
- 'S' => sec,
- 'of' => offset.to_s,
- 'sg' => @sg,
- }.to_json(*args)
- end
-end
-
-class Range
- def self.json_create(object)
- new(*object['a'])
- end
-
- def to_json(*args)
- {
- 'json_class' => self.class.name.to_s,
- 'a' => [ first, last, exclude_end? ]
- }.to_json(*args)
- end
-end
-
-class Struct
- def self.json_create(object)
- new(*object['v'])
- end
-
- def to_json(*args)
- klass = self.class.name.to_s
- klass.empty? and raise JSON::JSONError, "Only named structs are supported!"
- {
- 'json_class' => klass,
- 'v' => values,
- }.to_json(*args)
- end
-end
-
-class Exception
- def self.json_create(object)
- result = new(object['m'])
- result.set_backtrace object['b']
- result
- end
-
- def to_json(*args)
- {
- 'json_class' => self.class.name.to_s,
- 'm' => message,
- 'b' => backtrace,
- }.to_json(*args)
- end
-end
-
-class Regexp
- def self.json_create(object)
- new(object['s'], object['o'])
- end
-
- def to_json(*)
- {
- 'json_class' => self.class.name.to_s,
- 'o' => options,
- 's' => source,
- }.to_json
- end
-end
diff --git a/trunk/ext/json/lib/json/add/rails.rb b/trunk/ext/json/lib/json/add/rails.rb
deleted file mode 100644
index e86ed1aab9..0000000000
--- a/trunk/ext/json/lib/json/add/rails.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-# This file contains implementations of rails custom objects for
-# serialisation/deserialisation.
-
-unless Object.const_defined?(:JSON) and ::JSON.const_defined?(:JSON_LOADED) and
- ::JSON::JSON_LOADED
- require 'json'
-end
-
-class Object
- def self.json_create(object)
- obj = new
- for key, value in object
- next if key == 'json_class'
- instance_variable_set "@#{key}", value
- end
- obj
- end
-
- def to_json(*a)
- result = {
- 'json_class' => self.class.name
- }
- instance_variables.inject(result) do |r, name|
- r[name[1..-1]] = instance_variable_get name
- r
- end
- result.to_json(*a)
- end
-end
-
-class Symbol
- def to_json(*a)
- to_s.to_json(*a)
- end
-end
-
-module Enumerable
- def to_json(*a)
- to_a.to_json(*a)
- end
-end
-
-# class Regexp
-# def to_json(*)
-# inspect
-# end
-# end
-#
-# The above rails definition has some problems:
-#
-# 1. { 'foo' => /bar/ }.to_json # => "{foo: /bar/}"
-# This isn't valid JSON, because the regular expression syntax is not
-# defined in RFC 4627. (And unquoted strings are disallowed there, too.)
-# Though it is valid Javascript.
-#
-# 2. { 'foo' => /bar/mix }.to_json # => "{foo: /bar/mix}"
-# This isn't even valid Javascript.
-