brianmario-yajl-ruby 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/CHANGELOG.md +8 -1
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/benchmark/encode.rb +1 -1
- data/benchmark/encode_json_and_marshal.rb +1 -1
- data/benchmark/encode_json_and_yaml.rb +1 -1
- data/benchmark/parse.rb +1 -1
- data/benchmark/parse_json_and_marshal.rb +2 -2
- data/benchmark/parse_json_and_yaml.rb +1 -1
- data/benchmark/subjects/ohai.marshal_dump +0 -0
- data/benchmark/subjects/ohai.yml +975 -0
- data/lib/yajl/json_gem/encoding.rb +40 -0
- data/lib/yajl/json_gem/parsing.rb +26 -0
- data/lib/yajl/json_gem.rb +3 -58
- data/lib/yajl.rb +1 -1
- data/spec/json_gem_compatibility/compatibility_spec.rb +8 -0
- data/yajl-ruby.gemspec +7 -5
- metadata +7 -6
- data/benchmark/subjects/contacts.json +0 -1
- data/benchmark/subjects/contacts.marshal_dump +0 -0
- data/benchmark/subjects/contacts.yml +0 -114685
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'yajl' unless defined?(Yajl::Parser)
|
3
|
+
|
4
|
+
# NOTE: this is probably temporary until I can split out the JSON compat C code into it's own
|
5
|
+
# extension that can be included when this file is.
|
6
|
+
Yajl::Encoder.enable_json_gem_compatability
|
7
|
+
|
8
|
+
module JSON
|
9
|
+
def self.generate(obj, opts={})
|
10
|
+
begin
|
11
|
+
options_map = {}
|
12
|
+
if opts.has_key?(:indent)
|
13
|
+
options_map[:pretty] = true
|
14
|
+
options_map[:indent] = opts[:indent]
|
15
|
+
end
|
16
|
+
Yajl::Encoder.encode(obj, options_map)
|
17
|
+
rescue Yajl::ParseError => e
|
18
|
+
raise JSON::ParserError, e.message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.pretty_generate(obj, opts={})
|
23
|
+
begin
|
24
|
+
options_map = {}
|
25
|
+
options_map[:pretty] = true
|
26
|
+
options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
|
27
|
+
Yajl::Encoder.encode(obj, options_map)
|
28
|
+
rescue Yajl::ParseError => e
|
29
|
+
raise JSON::ParserError, e.message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.dump(obj, io=nil, *args)
|
34
|
+
begin
|
35
|
+
Yajl::Encoder.encode(obj, io)
|
36
|
+
rescue Yajl::ParseError => e
|
37
|
+
raise JSON::ParserError, e.message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'yajl' unless defined?(Yajl::Parser)
|
3
|
+
|
4
|
+
module JSON
|
5
|
+
class ParserError < Yajl::ParseError; end
|
6
|
+
|
7
|
+
def self.default_options
|
8
|
+
@default_options ||= {:symbolize_keys => false}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parse(str, opts=JSON.default_options)
|
12
|
+
begin
|
13
|
+
Yajl::Parser.parse(str, opts)
|
14
|
+
rescue Yajl::ParseError => e
|
15
|
+
raise JSON::ParserError, e.message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.load(input, *args)
|
20
|
+
begin
|
21
|
+
Yajl::Parser.parse(input, default_options)
|
22
|
+
rescue Yajl::ParseError => e
|
23
|
+
raise JSON::ParserError, e.message
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/yajl/json_gem.rb
CHANGED
@@ -1,67 +1,12 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'yajl' unless defined?(Yajl::Parser)
|
3
|
-
|
4
|
-
|
5
|
-
# extension that can be included when this file is.
|
6
|
-
Yajl::Encoder.enable_json_gem_compatability
|
7
|
-
|
8
|
-
module JSON
|
9
|
-
|
10
|
-
class ParserError < Yajl::ParseError; end
|
11
|
-
|
12
|
-
def self.parse(str, opts={})
|
13
|
-
begin
|
14
|
-
Yajl::Parser.parse(str, opts)
|
15
|
-
rescue Yajl::ParseError => e
|
16
|
-
raise JSON::ParserError, e.message
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.generate(obj, opts={})
|
21
|
-
begin
|
22
|
-
options_map = {}
|
23
|
-
if opts.has_key?(:indent)
|
24
|
-
options_map[:pretty] = true
|
25
|
-
options_map[:indent] = opts[:indent]
|
26
|
-
end
|
27
|
-
Yajl::Encoder.encode(obj, options_map)
|
28
|
-
rescue Yajl::ParseError => e
|
29
|
-
raise JSON::ParserError, e.message
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.pretty_generate(obj, opts={})
|
34
|
-
begin
|
35
|
-
options_map = {}
|
36
|
-
options_map[:pretty] = true
|
37
|
-
options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
|
38
|
-
Yajl::Encoder.encode(obj, options_map)
|
39
|
-
rescue Yajl::ParseError => e
|
40
|
-
raise JSON::ParserError, e.message
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.load(input, *args)
|
45
|
-
begin
|
46
|
-
Yajl::Parser.parse(input)
|
47
|
-
rescue Yajl::ParseError => e
|
48
|
-
raise JSON::ParserError, e.message
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.dump(obj, io=nil, *args)
|
53
|
-
begin
|
54
|
-
Yajl::Encoder.encode(obj, io)
|
55
|
-
rescue Yajl::ParseError => e
|
56
|
-
raise JSON::ParserError, e.message
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
3
|
+
require 'yajl/json_gem/parsing'
|
4
|
+
require 'yajl/json_gem/encoding'
|
60
5
|
|
61
6
|
module ::Kernel
|
62
7
|
def JSON(object, opts = {})
|
63
8
|
if object.respond_to? :to_s
|
64
|
-
JSON.parse(object.to_s, opts)
|
9
|
+
JSON.parse(object.to_s, JSON.default_options.merge(opts))
|
65
10
|
else
|
66
11
|
JSON.generate(object, opts)
|
67
12
|
end
|
data/lib/yajl.rb
CHANGED
@@ -45,6 +45,14 @@ describe "JSON Gem compatability API" do
|
|
45
45
|
JSON.respond_to?(:dump).should be_true
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should allow default parsing options be set with JSON.default_options" do
|
49
|
+
default = JSON.default_options[:symbolize_keys]
|
50
|
+
JSON.parse('{"foo": 1234}').should === {"foo" => 1234}
|
51
|
+
JSON.default_options[:symbolize_keys] = true
|
52
|
+
JSON.parse('{"foo": 1234}').should === {:foo => 1234}
|
53
|
+
JSON.default_options[:symbolize_keys] = default # ensure the rest of the test cases expect the default
|
54
|
+
end
|
55
|
+
|
48
56
|
context "ported tests for Unicode" do
|
49
57
|
it "should be able to encode and parse unicode" do
|
50
58
|
pending if RUBY_VERSION.include?('1.9') # FIXME: Some string encoding problem with 1.9
|
data/yajl-ruby.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{yajl-ruby}
|
5
|
-
s.version = "0.5.
|
5
|
+
s.version = "0.5.6"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Brian Lopez", "Lloyd Hilaiel"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-19}
|
10
10
|
s.email = %q{seniorlopez@gmail.com}
|
11
11
|
s.extensions = ["ext/extconf.rb"]
|
12
12
|
s.extra_rdoc_files = [
|
@@ -27,11 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
"benchmark/parse_json_and_marshal.rb",
|
28
28
|
"benchmark/parse_json_and_yaml.rb",
|
29
29
|
"benchmark/parse_stream.rb",
|
30
|
-
"benchmark/subjects/contacts.json",
|
31
|
-
"benchmark/subjects/contacts.marshal_dump",
|
32
|
-
"benchmark/subjects/contacts.yml",
|
33
30
|
"benchmark/subjects/item.json",
|
34
31
|
"benchmark/subjects/ohai.json",
|
32
|
+
"benchmark/subjects/ohai.marshal_dump",
|
33
|
+
"benchmark/subjects/ohai.yml",
|
35
34
|
"benchmark/subjects/twitter_search.json",
|
36
35
|
"benchmark/subjects/twitter_stream.json",
|
37
36
|
"benchmark/subjects/unicode.json",
|
@@ -71,6 +70,8 @@ Gem::Specification.new do |s|
|
|
71
70
|
"lib/yajl/gzip/stream_writer.rb",
|
72
71
|
"lib/yajl/http_stream.rb",
|
73
72
|
"lib/yajl/json_gem.rb",
|
73
|
+
"lib/yajl/json_gem/encoding.rb",
|
74
|
+
"lib/yajl/json_gem/parsing.rb",
|
74
75
|
"spec/encoding/encoding_spec.rb",
|
75
76
|
"spec/http/fixtures/http.bzip2.dump",
|
76
77
|
"spec/http/fixtures/http.deflate.dump",
|
@@ -145,6 +146,7 @@ Gem::Specification.new do |s|
|
|
145
146
|
s.homepage = %q{http://github.com/brianmario/yajl-ruby}
|
146
147
|
s.rdoc_options = ["--charset=UTF-8"]
|
147
148
|
s.require_paths = ["lib", "ext"]
|
149
|
+
s.rubyforge_project = %q{yajl-ruby}
|
148
150
|
s.rubygems_version = %q{1.3.4}
|
149
151
|
s.summary = %q{Ruby C bindings to the excellent Yajl JSON stream-based parser library.}
|
150
152
|
s.test_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brianmario-yajl-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Lopez
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-06-
|
13
|
+
date: 2009-06-19 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -37,11 +37,10 @@ files:
|
|
37
37
|
- benchmark/parse_json_and_marshal.rb
|
38
38
|
- benchmark/parse_json_and_yaml.rb
|
39
39
|
- benchmark/parse_stream.rb
|
40
|
-
- benchmark/subjects/contacts.json
|
41
|
-
- benchmark/subjects/contacts.marshal_dump
|
42
|
-
- benchmark/subjects/contacts.yml
|
43
40
|
- benchmark/subjects/item.json
|
44
41
|
- benchmark/subjects/ohai.json
|
42
|
+
- benchmark/subjects/ohai.marshal_dump
|
43
|
+
- benchmark/subjects/ohai.yml
|
45
44
|
- benchmark/subjects/twitter_search.json
|
46
45
|
- benchmark/subjects/twitter_stream.json
|
47
46
|
- benchmark/subjects/unicode.json
|
@@ -81,6 +80,8 @@ files:
|
|
81
80
|
- lib/yajl/gzip/stream_writer.rb
|
82
81
|
- lib/yajl/http_stream.rb
|
83
82
|
- lib/yajl/json_gem.rb
|
83
|
+
- lib/yajl/json_gem/encoding.rb
|
84
|
+
- lib/yajl/json_gem/parsing.rb
|
84
85
|
- spec/encoding/encoding_spec.rb
|
85
86
|
- spec/http/fixtures/http.bzip2.dump
|
86
87
|
- spec/http/fixtures/http.deflate.dump
|
@@ -173,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
174
|
version:
|
174
175
|
requirements: []
|
175
176
|
|
176
|
-
rubyforge_project:
|
177
|
+
rubyforge_project: yajl-ruby
|
177
178
|
rubygems_version: 1.2.0
|
178
179
|
signing_key:
|
179
180
|
specification_version: 3
|