rufus-json 1.0.4 → 1.0.5

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.5 released 2013/08/03
6
+
7
+ - ensure .dup stringifies keys when backend == NONE
8
+
9
+
5
10
  == rufus-json - 1.0.4 released 2013/03/06
6
11
 
7
12
  - add support for OJ (https://github.com/ohler55/oj)
data/Rakefile CHANGED
@@ -1,8 +1,5 @@
1
1
 
2
- $:.unshift('.') # 1.9.2
3
-
4
2
  require 'rubygems'
5
- require 'rubygems/user_interaction' if Gem::RubyGemsVersion == '1.5.0'
6
3
 
7
4
  require 'rake'
8
5
  require 'rake/clean'
@@ -69,17 +66,17 @@ end
69
66
  #end
70
67
 
71
68
 
69
+ ##
70
+ ## upload_rdoc
72
71
  #
73
- # upload_rdoc
74
-
75
- desc %{
76
- upload the rdoc to rubyforge
77
- }
78
- task :upload_rdoc => [ :clean, :rdoc ] do
79
-
80
- account = 'jmettraux@rubyforge.org'
81
- webdir = '/var/www/gforge-projects/rufus'
82
-
83
- sh "rsync -azv -e ssh rdoc/#{GEMSPEC.name} #{account}:#{webdir}/"
84
- end
72
+ #desc %{
73
+ # upload the rdoc to rubyforge
74
+ #}
75
+ #task :upload_rdoc => [ :clean, :rdoc ] do
76
+ #
77
+ # account = 'jmettraux@rubyforge.org'
78
+ # webdir = '/var/www/gforge-projects/rufus'
79
+ #
80
+ # sh "rsync -azv -e ssh rdoc/#{GEMSPEC.name} #{account}:#{webdir}/"
81
+ #end
85
82
 
data/lib/rufus/json.rb CHANGED
@@ -22,17 +22,15 @@
22
22
  # Made in Japan.
23
23
  #++
24
24
 
25
- require 'ostruct'
26
-
27
25
 
28
26
  module Rufus
29
27
  module Json
30
28
 
31
- VERSION = '1.0.4'
29
+ VERSION = '1.0.5'
32
30
 
33
31
  # The JSON / JSON pure decoder
34
32
  #
35
- JSON = OpenStruct.new(
33
+ JSON = {
36
34
  :encode => lambda { |o, opts|
37
35
  opts[:max_nesting] = false unless opts.has_key?(:max_nesting)
38
36
  if o.is_a?(Hash) or o.is_a?(Array)
@@ -54,11 +52,11 @@ module Json
54
52
  ).first },
55
53
  :error => lambda {
56
54
  ::JSON::ParserError }
57
- )
55
+ }
58
56
 
59
57
  # The Rails ActiveSupport::JSON decoder
60
58
  #
61
- ACTIVE_SUPPORT = OpenStruct.new(
59
+ ACTIVE_SUPPORT = {
62
60
  :encode => lambda { |o, opts|
63
61
  ActiveSupport::JSON.encode(o, opts) },
64
62
  :pretty_encode => lambda { |o|
@@ -67,12 +65,12 @@ module Json
67
65
  decode_e(s) || ActiveSupport::JSON.decode(s) },
68
66
  :error => lambda {
69
67
  RuntimeError }
70
- )
68
+ }
71
69
  ACTIVE = ACTIVE_SUPPORT
72
70
 
73
71
  # https://github.com/brianmario/yajl-ruby/
74
72
  #
75
- YAJL = OpenStruct.new(
73
+ YAJL = {
76
74
  :encode => lambda { |o, opts|
77
75
  Yajl::Encoder.encode(o, opts) },
78
76
  :pretty_encode => lambda { |o|
@@ -81,11 +79,11 @@ module Json
81
79
  Yajl::Parser.parse(s) },
82
80
  :error => lambda {
83
81
  ::Yajl::ParseError }
84
- )
82
+ }
85
83
 
86
84
  # https://github.com/ohler55/oj
87
85
  #
88
- OJ = OpenStruct.new(
86
+ OJ = {
89
87
  :encode => lambda { |o, opts|
90
88
  Oj.dump(syms_to_s(o), opts.merge(:symbol_keys => false)) },
91
89
  :pretty_encode => lambda { |o|
@@ -94,16 +92,16 @@ module Json
94
92
  Oj.load(s, :strict => true) },
95
93
  :error => lambda {
96
94
  ::Oj::ParseError }
97
- )
95
+ }
98
96
 
99
97
  # The "raise an exception because there's no backend" backend
100
98
  #
101
- NONE = OpenStruct.new(
99
+ NONE = {
102
100
  :encode => lambda { |o, opts| raise 'no JSON backend found' },
103
101
  :pretty_encode => lambda { |o| raise 'no JSON backend found' },
104
102
  :decode => lambda { |s| raise 'no JSON backend found' },
105
103
  :error => lambda { raise 'no JSON backend found' }
106
- )
104
+ }
107
105
 
108
106
  # In the given order, attempts to load a json lib and sets it as the
109
107
  # backend of rufus-json.
@@ -189,14 +187,14 @@ module Json
189
187
  #
190
188
  def self.encode(o, opts={})
191
189
 
192
- @backend.encode[o, opts]
190
+ @backend[:encode][o, opts]
193
191
  end
194
192
 
195
193
  # Pretty encoding
196
194
  #
197
195
  def self.pretty_encode(o)
198
196
 
199
- @backend.pretty_encode[o]
197
+ @backend[:pretty_encode][o]
200
198
  end
201
199
 
202
200
  # An alias for .encode
@@ -210,9 +208,9 @@ module Json
210
208
  #
211
209
  def self.decode(s)
212
210
 
213
- @backend.decode[s]
211
+ @backend[:decode][s]
214
212
 
215
- rescue @backend.error[] => e
213
+ rescue @backend[:error][] => e
216
214
  raise ParserError.new(e.message)
217
215
  end
218
216
 
@@ -229,7 +227,11 @@ module Json
229
227
  #
230
228
  def self.dup(o)
231
229
 
232
- (@backend == NONE) ? Marshal.load(Marshal.dump(o)) : decode(encode(o))
230
+ if @backend == NONE
231
+ syms_to_s(Marshal.load(Marshal.dump(o)))
232
+ else
233
+ decode(encode(o))
234
+ end
233
235
  end
234
236
 
235
237
  E_REGEX = /^\d+(\.\d+)?[eE][+-]?\d+$/
data/test/do_test.rb CHANGED
@@ -8,6 +8,7 @@
8
8
  raise "please run me with bundle exec ruby..." unless defined?(Bundler)
9
9
 
10
10
  require 'test/unit'
11
+
11
12
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
13
  require 'rufus/json'
13
14
 
@@ -0,0 +1,34 @@
1
+
2
+ #
3
+ # testing rufus-json
4
+ #
5
+ # Sat Aug 3 09:37:48 JST 2013
6
+ #
7
+ # Ishinomaki
8
+ #
9
+
10
+ require 'test/unit'
11
+
12
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ require 'rufus-json'
14
+
15
+
16
+ class NoBackendTest < Test::Unit::TestCase
17
+
18
+ def test_dup
19
+
20
+ Rufus::Json.backend = :none
21
+
22
+ d0 = { 'id' => 'nada' }
23
+ d1 = { :id => :nada }
24
+ d2 = { :id => { :tree => [ 'nada', {}, [] ] } }
25
+
26
+ assert_equal(
27
+ { 'id' => 'nada' }, Rufus::Json.dup(d0))
28
+ assert_equal(
29
+ { 'id' => 'nada' }, Rufus::Json.dup(d1))
30
+ assert_equal(
31
+ { 'id' => { 'tree' => [ 'nada', {}, [] ] } }, Rufus::Json.dup(d2))
32
+ end
33
+ end
34
+
data/test/test.rb CHANGED
@@ -8,6 +8,9 @@
8
8
  #R = `which ruby`.strip
9
9
  R = 'bundle exec ruby'
10
10
  P = File.dirname(__FILE__)
11
+
12
+ load "#{P}/no_backend_test.rb"
13
+
11
14
  $result = ''
12
15
 
13
16
  def do_test(command)
metadata CHANGED
@@ -1,47 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rufus-json
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 4
10
- version: 1.0.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - John Mettraux
14
9
  - Torsten Schoenebaum
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2013-03-06 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2013-08-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rake
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
33
23
  type: :development
34
- version_requirements: *id001
35
- description: One interface to various JSON ruby libs (yajl, oj, json, json_pure, json-jruby, active_support). Has a preference for yajl.
36
- email:
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ description: One interface to various JSON ruby libs (yajl, oj, json, json_pure, json-jruby,
32
+ active_support). Has a preference for yajl.
33
+ email:
37
34
  - jmettraux@gmail.com
38
35
  executables: []
39
-
40
36
  extensions: []
41
-
42
37
  extra_rdoc_files: []
43
-
44
- files:
38
+ files:
45
39
  - Rakefile
46
40
  - lib/rufus-json/automatic.rb
47
41
  - lib/rufus-json.rb
@@ -50,6 +44,7 @@ files:
50
44
  - test/test.rb
51
45
  - test/do_test.rb
52
46
  - test/backend_test.rb
47
+ - test/no_backend_test.rb
53
48
  - test/nesting20.rb
54
49
  - rufus-json.gemspec
55
50
  - CHANGELOG.txt
@@ -58,36 +53,26 @@ files:
58
53
  - README.rdoc
59
54
  homepage: http://github.com/jmettraux/rufus-json
60
55
  licenses: []
61
-
62
56
  post_install_message:
63
57
  rdoc_options: []
64
-
65
- require_paths:
58
+ require_paths:
66
59
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
60
+ required_ruby_version: !ruby/object:Gem::Requirement
68
61
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
67
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
85
72
  requirements: []
86
-
87
73
  rubyforge_project: rufus
88
- rubygems_version: 1.8.24
74
+ rubygems_version: 1.8.23
89
75
  signing_key:
90
76
  specification_version: 3
91
77
  summary: One interface to various JSON ruby libs, with a preference for yajl.
92
78
  test_files: []
93
-