summaryrefslogtreecommitdiff
path: root/ruby_2_2/ext/json/lib/json/add
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_2_2/ext/json/lib/json/add')
-rw-r--r--ruby_2_2/ext/json/lib/json/add/bigdecimal.rb28
-rw-r--r--ruby_2_2/ext/json/lib/json/add/complex.rb22
-rw-r--r--ruby_2_2/ext/json/lib/json/add/core.rb11
-rw-r--r--ruby_2_2/ext/json/lib/json/add/date.rb33
-rw-r--r--ruby_2_2/ext/json/lib/json/add/date_time.rb49
-rw-r--r--ruby_2_2/ext/json/lib/json/add/exception.rb30
-rw-r--r--ruby_2_2/ext/json/lib/json/add/ostruct.rb30
-rw-r--r--ruby_2_2/ext/json/lib/json/add/range.rb28
-rw-r--r--ruby_2_2/ext/json/lib/json/add/rational.rb22
-rw-r--r--ruby_2_2/ext/json/lib/json/add/regexp.rb29
-rw-r--r--ruby_2_2/ext/json/lib/json/add/struct.rb29
-rw-r--r--ruby_2_2/ext/json/lib/json/add/symbol.rb24
-rw-r--r--ruby_2_2/ext/json/lib/json/add/time.rb37
13 files changed, 0 insertions, 372 deletions
diff --git a/ruby_2_2/ext/json/lib/json/add/bigdecimal.rb b/ruby_2_2/ext/json/lib/json/add/bigdecimal.rb
deleted file mode 100644
index 0ef69f12e0..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/bigdecimal.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-defined?(::BigDecimal) or require 'bigdecimal'
-
-class BigDecimal
- # Import a JSON Marshalled object.
- #
- # method used for JSON marshalling support.
- def self.json_create(object)
- BigDecimal._load object['b']
- end
-
- # Marshal the object to JSON.
- #
- # method used for JSON marshalling support.
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'b' => _dump,
- }
- end
-
- # return the JSON value
- def to_json(*)
- as_json.to_json
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/complex.rb b/ruby_2_2/ext/json/lib/json/add/complex.rb
deleted file mode 100644
index d7ebebf5f7..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/complex.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-defined?(::Complex) or require 'complex'
-
-class Complex
- def self.json_create(object)
- Complex(object['r'], object['i'])
- end
-
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'r' => real,
- 'i' => imag,
- }
- end
-
- def to_json(*)
- as_json.to_json
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/core.rb b/ruby_2_2/ext/json/lib/json/add/core.rb
deleted file mode 100644
index 77d9dc0b20..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/core.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# This file requires the implementations of ruby core's custom objects for
-# serialisation/deserialisation.
-
-require 'json/add/date'
-require 'json/add/date_time'
-require 'json/add/exception'
-require 'json/add/range'
-require 'json/add/regexp'
-require 'json/add/struct'
-require 'json/add/symbol'
-require 'json/add/time'
diff --git a/ruby_2_2/ext/json/lib/json/add/date.rb b/ruby_2_2/ext/json/lib/json/add/date.rb
deleted file mode 100644
index 458d9eba96..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/date.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-require 'date'
-
-class Date
-
- # Deserializes JSON string by converting Julian year <tt>y</tt>, month
- # <tt>m</tt>, day <tt>d</tt> and Day of Calendar Reform <tt>sg</tt> to Date.
- def self.json_create(object)
- civil(*object.values_at('y', 'm', 'd', 'sg'))
- end
-
- alias start sg unless method_defined?(:start)
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'y' => year,
- 'm' => month,
- 'd' => day,
- 'sg' => start,
- }
- end
-
- # Stores class name (Date) with Julian year <tt>y</tt>, month <tt>m</tt>, day
- # <tt>d</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
- def to_json(*args)
- as_json.to_json(*args)
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/date_time.rb b/ruby_2_2/ext/json/lib/json/add/date_time.rb
deleted file mode 100644
index a1009cf5dc..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/date_time.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-require 'date'
-
-class DateTime
-
- # Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
- # day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
- # offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
- def self.json_create(object)
- args = object.values_at('y', 'm', 'd', 'H', 'M', 'S')
- of_a, of_b = object['of'].split('/')
- if of_b and of_b != '0'
- args << Rational(of_a.to_i, of_b.to_i)
- else
- args << of_a
- end
- args << object['sg']
- civil(*args)
- end
-
- alias start sg unless method_defined?(:start)
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'y' => year,
- 'm' => month,
- 'd' => day,
- 'H' => hour,
- 'M' => min,
- 'S' => sec,
- 'of' => offset.to_s,
- 'sg' => start,
- }
- end
-
- # Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
- # day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
- # offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
- def to_json(*args)
- as_json.to_json(*args)
- end
-end
-
-
diff --git a/ruby_2_2/ext/json/lib/json/add/exception.rb b/ruby_2_2/ext/json/lib/json/add/exception.rb
deleted file mode 100644
index f4b150d236..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/exception.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-
-class Exception
-
- # Deserializes JSON string by constructing new Exception object with message
- # <tt>m</tt> and backtrace <tt>b</tt> serialized with <tt>to_json</tt>
- def self.json_create(object)
- result = new(object['m'])
- result.set_backtrace object['b']
- result
- end
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'm' => message,
- 'b' => backtrace,
- }
- end
-
- # Stores class name (Exception) with message <tt>m</tt> and backtrace array
- # <tt>b</tt> as JSON string
- def to_json(*args)
- as_json.to_json(*args)
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/ostruct.rb b/ruby_2_2/ext/json/lib/json/add/ostruct.rb
deleted file mode 100644
index a62f92f59b..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/ostruct.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-require 'ostruct'
-
-class OpenStruct
-
- # Deserializes JSON string by constructing new Struct object with values
- # <tt>v</tt> serialized by <tt>to_json</tt>.
- def self.json_create(object)
- new(object['t'] || object[:t])
- end
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- klass = self.class.name
- klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
- {
- JSON.create_id => klass,
- 't' => table,
- }
- end
-
- # Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a
- # JSON string.
- def to_json(*args)
- as_json.to_json(*args)
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/range.rb b/ruby_2_2/ext/json/lib/json/add/range.rb
deleted file mode 100644
index 0df382c60a..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/range.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-
-class Range
-
- # Deserializes JSON string by constructing new Range object with arguments
- # <tt>a</tt> serialized by <tt>to_json</tt>.
- def self.json_create(object)
- new(*object['a'])
- end
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'a' => [ first, last, exclude_end? ]
- }
- end
-
- # Stores class name (Range) with JSON array of arguments <tt>a</tt> which
- # include <tt>first</tt> (integer), <tt>last</tt> (integer), and
- # <tt>exclude_end?</tt> (boolean) as JSON string.
- def to_json(*args)
- as_json.to_json(*args)
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/rational.rb b/ruby_2_2/ext/json/lib/json/add/rational.rb
deleted file mode 100644
index 867cd92f05..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/rational.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-defined?(::Rational) or require 'rational'
-
-class Rational
- def self.json_create(object)
- Rational(object['n'], object['d'])
- end
-
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'n' => numerator,
- 'd' => denominator,
- }
- end
-
- def to_json(*)
- as_json.to_json
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/regexp.rb b/ruby_2_2/ext/json/lib/json/add/regexp.rb
deleted file mode 100644
index 9adf06c8f6..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/regexp.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-
-class Regexp
-
- # Deserializes JSON string by constructing new Regexp object with source
- # <tt>s</tt> (Regexp or String) and options <tt>o</tt> serialized by
- # <tt>to_json</tt>
- def self.json_create(object)
- new(object['s'], object['o'])
- end
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'o' => options,
- 's' => source,
- }
- end
-
- # Stores class name (Regexp) with options <tt>o</tt> and source <tt>s</tt>
- # (Regexp or String) as JSON string
- def to_json(*)
- as_json.to_json
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/struct.rb b/ruby_2_2/ext/json/lib/json/add/struct.rb
deleted file mode 100644
index e1e24800d0..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/struct.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-
-class Struct
-
- # Deserializes JSON string by constructing new Struct object with values
- # <tt>v</tt> serialized by <tt>to_json</tt>.
- def self.json_create(object)
- new(*object['v'])
- end
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- klass = self.class.name
- klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
- {
- JSON.create_id => klass,
- 'v' => values,
- }
- end
-
- # Stores class name (Struct) with Struct values <tt>v</tt> as a JSON string.
- # Only named structs are supported.
- def to_json(*args)
- as_json.to_json(*args)
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/symbol.rb b/ruby_2_2/ext/json/lib/json/add/symbol.rb
deleted file mode 100644
index 6df77cab09..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/symbol.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-
-class Symbol
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 's' => to_s,
- }
- end
-
- # Stores class name (Symbol) with String representation of Symbol as a JSON string.
- def to_json(*a)
- as_json.to_json(*a)
- end
-
- # Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
- def self.json_create(o)
- o['s'].to_sym
- end
-end
diff --git a/ruby_2_2/ext/json/lib/json/add/time.rb b/ruby_2_2/ext/json/lib/json/add/time.rb
deleted file mode 100644
index 25cec9fe91..0000000000
--- a/ruby_2_2/ext/json/lib/json/add/time.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
- require 'json'
-end
-
-class Time
-
- # Deserializes JSON string by converting time since epoch to Time
- def self.json_create(object)
- if usec = object.delete('u') # used to be tv_usec -> tv_nsec
- object['n'] = usec * 1000
- end
- if instance_methods.include?(:tv_nsec)
- at(object['s'], Rational(object['n'], 1000))
- else
- at(object['s'], object['n'] / 1000)
- end
- end
-
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
- def as_json(*)
- nanoseconds = [ tv_usec * 1000 ]
- respond_to?(:tv_nsec) and nanoseconds << tv_nsec
- nanoseconds = nanoseconds.max
- {
- JSON.create_id => self.class.name,
- 's' => tv_sec,
- 'n' => nanoseconds,
- }
- end
-
- # Stores class name (Time) with number of seconds since epoch and number of
- # microseconds for Time as JSON string
- def to_json(*args)
- as_json.to_json(*args)
- end
-end