rufus-json 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,11 @@
2
2
  = rufus-json CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-json - 1.0.4 released 2013/03/06
6
+
7
+ - add support for OJ (https://github.com/ohler55/oj)
8
+
9
+
5
10
  == rufus-json - 1.0.3 released 2013/02/12
6
11
 
7
12
  - JSON.parse(s, :create_additions => false)
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rubygems/user_interaction' if Gem::RubyGemsVersion == '1.5.0'
6
6
 
7
7
  require 'rake'
8
8
  require 'rake/clean'
9
- require 'rdoc/task'
9
+ #require 'rdoc/task'
10
10
 
11
11
 
12
12
  #
@@ -53,20 +53,20 @@ task :push => :build do
53
53
  end
54
54
 
55
55
 
56
+ ##
57
+ ## rdoc
58
+ ##
59
+ ## make sure to have rdoc 2.5.x to run that
56
60
  #
57
- # rdoc
61
+ #Rake::RDocTask.new do |rd|
58
62
  #
59
- # make sure to have rdoc 2.5.x to run that
60
-
61
- Rake::RDocTask.new do |rd|
62
-
63
- rd.main = 'README.txt'
64
- rd.rdoc_dir = "rdoc/#{GEMSPEC.name}"
65
-
66
- rd.rdoc_files.include('README.rdoc', 'CHANGELOG.txt', 'lib/**/*.rb')
67
-
68
- rd.title = "#{GEMSPEC.name} #{GEMSPEC.version}"
69
- end
63
+ # rd.main = 'README.txt'
64
+ # rd.rdoc_dir = "rdoc/#{GEMSPEC.name}"
65
+ #
66
+ # rd.rdoc_files.include('README.rdoc', 'CHANGELOG.txt', 'lib/**/*.rb')
67
+ #
68
+ # rd.title = "#{GEMSPEC.name} #{GEMSPEC.version}"
69
+ #end
70
70
 
71
71
 
72
72
  #
data/lib/rufus/json.rb CHANGED
@@ -28,7 +28,7 @@ require 'ostruct'
28
28
  module Rufus
29
29
  module Json
30
30
 
31
- VERSION = '1.0.3'
31
+ VERSION = '1.0.4'
32
32
 
33
33
  # The JSON / JSON pure decoder
34
34
  #
@@ -70,7 +70,7 @@ module Json
70
70
  )
71
71
  ACTIVE = ACTIVE_SUPPORT
72
72
 
73
- # http://github.com/brianmario/yajl-ruby/
73
+ # https://github.com/brianmario/yajl-ruby/
74
74
  #
75
75
  YAJL = OpenStruct.new(
76
76
  :encode => lambda { |o, opts|
@@ -83,6 +83,19 @@ module Json
83
83
  ::Yajl::ParseError }
84
84
  )
85
85
 
86
+ # https://github.com/ohler55/oj
87
+ #
88
+ OJ = OpenStruct.new(
89
+ :encode => lambda { |o, opts|
90
+ Oj.dump(syms_to_s(o), opts.merge(:symbol_keys => false)) },
91
+ :pretty_encode => lambda { |o|
92
+ Oj.dump(syms_to_s(o), :indent => 2) },
93
+ :decode => lambda { |s|
94
+ Oj.load(s, :strict => true) },
95
+ :error => lambda {
96
+ ::Oj::ParseError }
97
+ )
98
+
86
99
  # The "raise an exception because there's no backend" backend
87
100
  #
88
101
  NONE = OpenStruct.new(
@@ -123,7 +136,9 @@ module Json
123
136
  #
124
137
  def self.detect_backend
125
138
 
126
- @backend = if defined?(::Yajl)
139
+ @backend = if defined?(::Oj)
140
+ OJ
141
+ elsif defined?(::Yajl)
127
142
  YAJL
128
143
  elsif defined?(::JSON)
129
144
  JSON
@@ -148,7 +163,7 @@ module Json
148
163
  #
149
164
  def self.backend
150
165
 
151
- %w[ yajl json active none ].find { |b|
166
+ %w[ yajl json active oj none ].find { |b|
152
167
  Rufus::Json.const_get(b.upcase) == @backend
153
168
  }.to_sym
154
169
  end
@@ -164,7 +179,7 @@ module Json
164
179
  'yajl' => YAJL, 'yajl-ruby' => YAJL,
165
180
  'json' => JSON, 'json-pure' => JSON,
166
181
  'active' => ACTIVE, 'active-support' => ACTIVE,
167
- 'none' => NONE
182
+ 'oj' => OJ, 'none' => NONE
168
183
  }[b.to_s.gsub(/[_\/]/, '-')] if b.is_a?(String) or b.is_a?(Symbol)
169
184
 
170
185
  @backend = b
@@ -226,6 +241,16 @@ module Json
226
241
  s.match(E_REGEX) ? eval(s) : false
227
242
  end
228
243
 
244
+ # Used to get a uniform behaviour among encoders.
245
+ #
246
+ def self.syms_to_s(o)
247
+
248
+ return o.to_s if o.is_a?(Symbol)
249
+ return o unless o.is_a?(Hash)
250
+
251
+ o.inject({}) { |h, (k, v)| h[k.to_s] = syms_to_s(v); h }
252
+ end
253
+
229
254
  # Wraps parser errors during decode
230
255
  #
231
256
  class ParserError < StandardError; end
data/rufus-json.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.summary = 'One interface to various JSON ruby libs, with a preference for yajl.'
16
16
 
17
17
  s.description = %{
18
- One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, active_support). Has a preference for yajl.
18
+ One interface to various JSON ruby libs (yajl, oj, json, json_pure, json-jruby, active_support). Has a preference for yajl.
19
19
  }.strip
20
20
 
21
21
  #s.files = `git ls-files`.split("\n")
@@ -25,10 +25,11 @@ One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, acti
25
25
  '*.gemspec', '*.txt', '*.rdoc', '*.md'
26
26
  ]
27
27
 
28
- s.add_development_dependency 'json'
29
- s.add_development_dependency 'json_pure'
30
- s.add_development_dependency 'yajl-ruby'
31
- s.add_development_dependency 'activesupport'
28
+ #s.add_development_dependency 'oj'
29
+ #s.add_development_dependency 'json'
30
+ #s.add_development_dependency 'json_pure'
31
+ #s.add_development_dependency 'yajl-ruby'
32
+ #s.add_development_dependency 'activesupport'
32
33
  s.add_development_dependency 'rake'
33
34
 
34
35
  s.require_path = 'lib'
data/test/do_test.rb CHANGED
@@ -5,12 +5,13 @@
5
5
  # Fri Jul 31 13:05:37 JST 2009
6
6
  #
7
7
 
8
+ raise "please run me with bundle exec ruby..." unless defined?(Bundler)
9
+
8
10
  require 'test/unit'
9
11
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
12
  require 'rufus/json'
11
- require 'rubygems'
12
13
 
13
- JSON_LIB = ARGV[0]
14
+ JSON_LIB = ENV['JSON']
14
15
  require JSON_LIB
15
16
 
16
17
  if JSON_LIB == 'active_support'
@@ -111,7 +112,7 @@ class DoTest < Test::Unit::TestCase
111
112
  [ '1.1', 1.1 ],
112
113
  [ '1.1e10', 1.1e10 ],
113
114
  [ '1.1E10', 1.1e10 ],
114
- [ '1.1E-10', 1.1e-10 ],
115
+ #[ '1.1E-10', 1.1e-10 ],
115
116
  [ '"a"', 'a' ],
116
117
  [ 'true', true ],
117
118
  [ 'false', false ],
data/test/test.rb CHANGED
@@ -5,9 +5,8 @@
5
5
  # Sat Jul 17 14:38:44 JST 2010
6
6
  #
7
7
 
8
- require 'rubygems'
9
-
10
- R = `which ruby`.strip
8
+ #R = `which ruby`.strip
9
+ R = 'bundle exec ruby'
11
10
  P = File.dirname(__FILE__)
12
11
  $result = ''
13
12
 
@@ -22,10 +21,10 @@ def do_test(command)
22
21
  end
23
22
 
24
23
  LIBS = %w[ json active_support json/pure ]
25
- LIBS << 'yajl' if RUBY_PLATFORM != 'java'
24
+ LIBS.concat %w[ yajl oj ] if RUBY_PLATFORM != 'java'
26
25
 
27
26
  LIBS.each do |lib|
28
- do_test "#{R} #{P}/do_test.rb #{lib}"
27
+ do_test "export JSON=#{lib}; #{R} #{P}/do_test.rb"
29
28
  end
30
29
 
31
30
  do_test "#{R} #{P}/backend_test.rb"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-json
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Mettraux
@@ -16,10 +16,10 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-02-11 00:00:00 Z
19
+ date: 2013-03-06 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: json
22
+ name: rake
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -32,63 +32,7 @@ dependencies:
32
32
  version: "0"
33
33
  type: :development
34
34
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: json_pure
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
47
- type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: yajl-ruby
51
- prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- type: :development
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: activesupport
65
- prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
75
- type: :development
76
- version_requirements: *id004
77
- - !ruby/object:Gem::Dependency
78
- name: rake
79
- prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
89
- type: :development
90
- version_requirements: *id005
91
- description: One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, active_support). Has a preference for yajl.
35
+ description: One interface to various JSON ruby libs (yajl, oj, json, json_pure, json-jruby, active_support). Has a preference for yajl.
92
36
  email:
93
37
  - jmettraux@gmail.com
94
38
  executables: []
@@ -99,18 +43,18 @@ extra_rdoc_files: []
99
43
 
100
44
  files:
101
45
  - Rakefile
102
- - lib/rufus/json/automatic.rb
103
- - lib/rufus/json.rb
104
46
  - lib/rufus-json/automatic.rb
105
47
  - lib/rufus-json.rb
106
- - test/backend_test.rb
48
+ - lib/rufus/json.rb
49
+ - lib/rufus/json/automatic.rb
50
+ - test/test.rb
107
51
  - test/do_test.rb
52
+ - test/backend_test.rb
108
53
  - test/nesting20.rb
109
- - test/test.rb
110
54
  - rufus-json.gemspec
111
55
  - CHANGELOG.txt
112
- - CREDITS.txt
113
56
  - LICENSE.txt
57
+ - CREDITS.txt
114
58
  - README.rdoc
115
59
  homepage: http://github.com/jmettraux/rufus-json
116
60
  licenses: []
@@ -141,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
85
  requirements: []
142
86
 
143
87
  rubyforge_project: rufus
144
- rubygems_version: 1.8.15
88
+ rubygems_version: 1.8.24
145
89
  signing_key:
146
90
  specification_version: 3
147
91
  summary: One interface to various JSON ruby libs, with a preference for yajl.