oj 2.12.11 → 2.12.12

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.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ %w(lib ext test).each do |dir|
5
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
6
+ end
7
+
8
+ require 'oj'
9
+
10
+ def create_item(doc)
11
+ item_id = doc['source']
12
+ # ...
13
+ puts item_id
14
+ end
15
+
16
+ File.open('log.json') { |f|
17
+ Oj::load(f, mode: :compat) { |doc|
18
+ begin
19
+ create_item(doc) if doc['msgType'] == 1
20
+ rescue Exception => e
21
+ puts "*** #{e.class}: #{e.message}"
22
+ end
23
+ }
24
+ }
@@ -0,0 +1,11 @@
1
+ %w(lib ext test).each do |dir|
2
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
3
+ end
4
+ require 'oj'
5
+ require 'json'
6
+
7
+ Oj::Doc.open([{:name => "T-Shirt"}].to_json) do |doc|
8
+ doc.each_child do |child|
9
+ p child.fetch("name")
10
+ end
11
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'helper'
7
+
8
+ class Handler
9
+ def initialize
10
+ @state = []
11
+ end
12
+
13
+ def hash_start
14
+ @state << {}
15
+ @state.last
16
+ end
17
+
18
+ def hash_end
19
+ @state.pop
20
+ end
21
+
22
+ def hash_set(h,k,v)
23
+ h.store(k,v)
24
+ end
25
+
26
+ def array_start
27
+ @state << []
28
+ @state.last
29
+ end
30
+
31
+
32
+ def array_end
33
+ @state.pop
34
+ end
35
+
36
+ def array_append(a,v)
37
+ a << v
38
+ end
39
+
40
+ def error(message, line, column); p "ERROR: #{message}" end
41
+ end
42
+
43
+ handler = Handler.new
44
+ def handler.add_value(v)
45
+ p v
46
+ end
47
+
48
+ Oj.sc_parse(handler, StringIO.new('{"a":"b","c":[1,2,{"d":"e"}]}[4,5,6]'))
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'helper'
7
+ require 'oj'
8
+
9
+ class ObjectFolder < Minitest::Test
10
+ class Raccoon
11
+ attr_accessor :name
12
+
13
+ def initialize(name)
14
+ @name = name
15
+ end
16
+
17
+ def as_json(options={})
18
+ {:name => @name}.merge(options)
19
+ end
20
+ end
21
+
22
+ def setup
23
+ @default_options = Oj.default_options
24
+ end
25
+
26
+ def teardown
27
+ Oj.default_options = @default_options
28
+ end
29
+
30
+ def test_as_json_options
31
+ Oj.mimic_JSON()
32
+ raccoon = Raccoon.new('Rocket')
33
+ json = raccoon.to_json()
34
+ assert_equal(json, '{"name":"Rocket"}')
35
+
36
+ json = raccoon.to_json(:occupation => 'bounty hunter')
37
+ # depending on the ruby version the order of the hash members maybe different.
38
+ if (json.start_with?('{"name'))
39
+ assert_equal(json, '{"name":"Rocket","occupation":"bounty hunter"}')
40
+ else
41
+ assert_equal(json, '{"occupation":"bounty hunter","name":"Rocket"}')
42
+ end
43
+ end
44
+
45
+ end
@@ -1,19 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- $VERBOSE = true
5
-
6
4
  %w(lib ext test).each do |dir|
7
5
  $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
8
6
  end
9
7
 
10
- require 'rubygems' if RUBY_VERSION.start_with?('1.8.')
11
8
  require 'oj'
12
9
 
13
- Oj.mimic_JSON
14
-
15
- #puts Oj.default_options
16
-
17
- range = ("01".."12")
18
10
 
19
- puts Oj.dump(range)
11
+ Thread.new do
12
+ string_io = StringIO.new('{"foo":"bar"}')
13
+ Oj.load(string_io)
14
+ string_io.rewind
15
+ puts string_io.read
16
+ end.join
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
+ # required. That can be set in the RUBYOPT environment variable.
6
+ # export RUBYOPT=-w
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'oj'
14
+
15
+ A = Struct.new(:a,:b,:c,:d)
16
+ B = Struct.new(:e,:f)
17
+
18
+ obj = [A.new(55, B.new(1, 'X'), B.new(2, 'Y'), 3)]
19
+
20
+ s = Oj.dump(obj, :mode => :object)
21
+
22
+ 100000.times do
23
+ Oj.load(s, :mode => :object)
24
+ # ds = Oj.dump(o, :mode => :object)
25
+ # if ds != s
26
+ # puts ds
27
+ # raise "holy crap"
28
+ # end
29
+ end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ %w(lib ext test).each do |dir|
7
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
8
+ end
9
+
10
+ require 'minitest'
11
+ require 'minitest/autorun'
12
+ require 'oj'
13
+
14
+ Oj.mimic_JSON
15
+
16
+ require 'rails/all'
17
+ require 'active_model'
18
+ require 'active_model_serializers'
19
+ require 'active_support/json'
20
+
21
+ #Oj.mimic_JSON
22
+
23
+ class Category
24
+ include ActiveModel::Model
25
+ include ActiveModel::SerializerSupport
26
+
27
+ attr_accessor :id, :name
28
+
29
+ def initialize(id, name)
30
+ @id = id
31
+ @name = name
32
+ end
33
+ end
34
+
35
+ class CategorySerializer < ActiveModel::Serializer
36
+ attributes :id, :name
37
+ end
38
+
39
+ class MimicRails < Minitest::Test
40
+
41
+ def test_dump_object
42
+ Oj.default_options= {:indent => 0}
43
+ category = Category.new(1, 'test')
44
+ serializer = CategorySerializer.new(category)
45
+
46
+ json = serializer.to_json()
47
+ puts "*** serializer.to_json() #{serializer.to_json()}"
48
+ assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
49
+
50
+ json = serializer.as_json()
51
+ puts "*** serializer.as_json() #{serializer.as_json()}"
52
+ assert_equal({"category" => {:id => 1, :name => "test"}}, json)
53
+
54
+ json = JSON.dump(serializer)
55
+ puts "*** JSON.dump(serializer) #{JSON.dump(serializer)}"
56
+ assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
57
+ end
58
+
59
+ end # MimicRails
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ %w(lib ext).each do |dir|
5
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
6
+ end
7
+
8
+ require 'stringio'
9
+ require 'oj'
10
+
11
+
12
+ filename = File.join(File.dirname(__FILE__), 'day.json')
13
+ File.open(filename, "w") do |f|
14
+ w = Oj::StreamWriter.new(f, :indent => -1)
15
+ 390.times do |i|
16
+ w.push_object()
17
+ w.push_value(12, 'msgType')
18
+ w.push_value(1, 'version')
19
+ w.push_value(1_400_074_200 + i * 60, 'bar')
20
+ w.push_value('TBC', 'source')
21
+ w.push_array('timebars')
22
+ w.push_object()
23
+ w.push_value('aapl_24', 'asset')
24
+ w.push_value(91.87, 'close')
25
+ w.pop()
26
+ w.pop()
27
+ w.pop()
28
+ end
29
+ f.write("\n")
30
+ end
31
+
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'helper'
7
+
8
+ require 'zlib'
9
+
10
+ File.open('test.json.gz', 'r') do |file|
11
+ Zlib::GzipReader.wrap(file) do |f2|
12
+ puts "*** f2: #{f2}"
13
+ Oj.load(f2) do |val|
14
+ puts val
15
+ end
16
+ end
17
+ end
18
+
19
+ =begin
20
+ And a json file with the following contents (then gzipped):
21
+
22
+ {"a":2}
23
+ {"b":2}
24
+ The output is:
25
+
26
+ {"a"=>2}
27
+ {"b"=>2}
28
+ bin/test:8:in `load': undefined method `new' for #<EOFError: end of file reached> (NoMethodError)
29
+ from bin/test:8:in `block (2 levels) in <main>'
30
+ from bin/test:7:in `wrap'
31
+ from bin/test:7:in `block in <main>'
32
+ from bin/test:6:in `open'
33
+ from bin/test:6:in `<main>'
34
+ =end
metadata CHANGED
@@ -1,65 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.11
5
- prerelease:
4
+ version: 2.12.12
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Ohler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-08-02 00:00:00.000000000 Z
11
+ date: 2015-08-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake-compiler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0.9'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0.9'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '5'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '5'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rails
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '4'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '4'
62
- description: ! 'The fastest JSON parser and object serializer. '
55
+ description: 'The fastest JSON parser and object serializer. '
63
56
  email: peter@ohler.com
64
57
  executables: []
65
58
  extensions:
@@ -67,71 +60,79 @@ extensions:
67
60
  extra_rdoc_files:
68
61
  - README.md
69
62
  files:
70
- - lib/oj/active_support_helper.rb
71
- - lib/oj/bag.rb
72
- - lib/oj/error.rb
73
- - lib/oj/mimic.rb
74
- - lib/oj/saj.rb
75
- - lib/oj/schandler.rb
76
- - lib/oj/version.rb
77
- - lib/oj.rb
78
- - ext/oj/extconf.rb
63
+ - LICENSE
64
+ - README.md
79
65
  - ext/oj/buf.h
80
- - ext/oj/cache8.h
81
- - ext/oj/circarray.h
82
- - ext/oj/encode.h
83
- - ext/oj/err.h
84
- - ext/oj/hash.h
85
- - ext/oj/odd.h
86
- - ext/oj/oj.h
87
- - ext/oj/parse.h
88
- - ext/oj/reader.h
89
- - ext/oj/resolve.h
90
- - ext/oj/val_stack.h
91
66
  - ext/oj/cache8.c
67
+ - ext/oj/cache8.h
92
68
  - ext/oj/circarray.c
69
+ - ext/oj/circarray.h
93
70
  - ext/oj/compat.c
94
71
  - ext/oj/dump.c
72
+ - ext/oj/encode.h
95
73
  - ext/oj/err.c
74
+ - ext/oj/err.h
75
+ - ext/oj/extconf.rb
96
76
  - ext/oj/fast.c
97
77
  - ext/oj/hash.c
78
+ - ext/oj/hash.h
98
79
  - ext/oj/hash_test.c
99
80
  - ext/oj/object.c
100
81
  - ext/oj/odd.c
82
+ - ext/oj/odd.h
101
83
  - ext/oj/oj.c
84
+ - ext/oj/oj.h
102
85
  - ext/oj/parse.c
86
+ - ext/oj/parse.h
103
87
  - ext/oj/reader.c
88
+ - ext/oj/reader.h
104
89
  - ext/oj/resolve.c
90
+ - ext/oj/resolve.h
105
91
  - ext/oj/saj.c
106
92
  - ext/oj/scp.c
107
93
  - ext/oj/sparse.c
108
94
  - ext/oj/strict.c
109
95
  - ext/oj/val_stack.c
96
+ - ext/oj/val_stack.h
97
+ - lib/oj.rb
98
+ - lib/oj/active_support_helper.rb
99
+ - lib/oj/bag.rb
100
+ - lib/oj/error.rb
101
+ - lib/oj/mimic.rb
102
+ - lib/oj/saj.rb
103
+ - lib/oj/schandler.rb
104
+ - lib/oj/version.rb
110
105
  - test/_test_active.rb
111
106
  - test/_test_active_mimic.rb
112
107
  - test/_test_mimic_rails.rb
113
108
  - test/bug.rb
109
+ - test/bug2.rb
110
+ - test/bug3.rb
111
+ - test/bug_fast.rb
112
+ - test/bug_load.rb
113
+ - test/example.rb
114
114
  - test/files.rb
115
115
  - test/helper.rb
116
+ - test/io.rb
116
117
  - test/isolated/shared.rb
117
118
  - test/isolated/test_mimic_after.rb
118
119
  - test/isolated/test_mimic_alone.rb
120
+ - test/isolated/test_mimic_as_json.rb
119
121
  - test/isolated/test_mimic_before.rb
120
122
  - test/isolated/test_mimic_define.rb
121
123
  - test/isolated/test_mimic_rails_after.rb
122
124
  - test/isolated/test_mimic_rails_before.rb
125
+ - test/mod.rb
123
126
  - test/perf.rb
124
- - test/perf1.rb
125
- - test/perf2.rb
126
127
  - test/perf_compat.rb
127
128
  - test/perf_fast.rb
128
129
  - test/perf_file.rb
129
- - test/perf_obj_old.rb
130
130
  - test/perf_object.rb
131
131
  - test/perf_saj.rb
132
132
  - test/perf_scp.rb
133
133
  - test/perf_simple.rb
134
134
  - test/perf_strict.rb
135
+ - test/sample.rb
135
136
  - test/sample/change.rb
136
137
  - test/sample/dir.rb
137
138
  - test/sample/doc.rb
@@ -144,49 +145,47 @@ files:
144
145
  - test/sample/rect.rb
145
146
  - test/sample/shape.rb
146
147
  - test/sample/text.rb
147
- - test/sample.rb
148
148
  - test/sample_json.rb
149
- - test/test_bigd.rb
149
+ - test/struct.rb
150
150
  - test/test_compat.rb
151
151
  - test/test_debian.rb
152
152
  - test/test_fast.rb
153
153
  - test/test_file.rb
154
154
  - test/test_gc.rb
155
155
  - test/test_object.rb
156
- - test/test_range.rb
157
156
  - test/test_saj.rb
158
157
  - test/test_scp.rb
158
+ - test/test_serializer.rb
159
159
  - test/test_strict.rb
160
160
  - test/test_various.rb
161
161
  - test/test_writer.rb
162
- - LICENSE
163
- - README.md
162
+ - test/write_timebars.rb
163
+ - test/zip.rb
164
164
  homepage: http://www.ohler.com/oj
165
165
  licenses:
166
166
  - MIT
167
+ metadata: {}
167
168
  post_install_message:
168
169
  rdoc_options:
169
- - --main
170
+ - "--main"
170
171
  - README.md
171
172
  require_paths:
172
173
  - lib
173
174
  - ext
174
175
  required_ruby_version: !ruby/object:Gem::Requirement
175
- none: false
176
176
  requirements:
177
- - - ! '>='
177
+ - - ">="
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  required_rubygems_version: !ruby/object:Gem::Requirement
181
- none: false
182
181
  requirements:
183
- - - ! '>='
182
+ - - ">="
184
183
  - !ruby/object:Gem::Version
185
184
  version: '0'
186
185
  requirements: []
187
186
  rubyforge_project: oj
188
- rubygems_version: 1.8.23.2
187
+ rubygems_version: 2.4.5
189
188
  signing_key:
190
- specification_version: 3
189
+ specification_version: 4
191
190
  summary: A fast JSON parser and serializer.
192
191
  test_files: []