rufus-json 0.2.1 → 0.2.2

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 - 0.2.2 released 2010/05/26
6
+
7
+ - Unified Rufus::Json::ParserError (Torsten Schoenebaum)
8
+
9
+
5
10
  == rufus-json - 0.2.1 released 2010/05/03
6
11
 
7
12
  - ActiveSupport::JSON.encode(o) instead of o.to_json
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, acti
31
31
  }
32
32
  gem.email = 'jmettraux@gmail.com'
33
33
  gem.homepage = 'http://github.com/jmettraux/rufus-json/'
34
- gem.authors = [ 'John Mettraux' ]
34
+ gem.authors = [ 'John Mettraux', 'Torsten Schoenebaum' ]
35
35
  gem.rubyforge_project = 'rufus'
36
36
 
37
37
  gem.test_file = 'test/test.rb'
@@ -41,7 +41,9 @@ One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, acti
41
41
  gem.add_development_dependency 'activesupport'
42
42
  #gem.add_development_dependency 'json_pure'
43
43
  #gem.add_development_dependency 'json-jruby'
44
- gem.add_development_dependency 'yard', '>= 0'
44
+ gem.add_development_dependency 'rake'
45
+ gem.add_development_dependency 'yard'
46
+ gem.add_development_dependency 'jeweler'
45
47
 
46
48
  # gemspec spec : http://www.rubygems.org/read/chapter/20
47
49
  end
data/lib/rufus/json.rb CHANGED
@@ -26,20 +26,22 @@
26
26
  module Rufus
27
27
  module Json
28
28
 
29
- VERSION = '0.2.1'
29
+ VERSION = '0.2.2'
30
30
 
31
31
  # The JSON / JSON pure decoder
32
32
  #
33
33
  JSON = [
34
34
  lambda { |o| o.to_json },
35
- lambda { |s| ::JSON.parse(s, :max_nesting => nil) }
35
+ lambda { |s| ::JSON.parse(s, :max_nesting => nil) },
36
+ lambda { ::JSON::ParserError }
36
37
  ]
37
38
 
38
39
  # The Rails ActiveSupport::JSON decoder
39
40
  #
40
41
  ACTIVE_SUPPORT = [
41
42
  lambda { |o| ActiveSupport::JSON.encode(o) },
42
- lambda { |s| ActiveSupport::JSON.decode(s) }
43
+ lambda { |s| ActiveSupport::JSON.decode(s) },
44
+ lambda { ::ActiveSupport::JSON::ParseError }
43
45
  ]
44
46
  ACTIVE = ACTIVE_SUPPORT
45
47
 
@@ -47,12 +49,17 @@ module Json
47
49
  #
48
50
  YAJL = [
49
51
  lambda { |o| Yajl::Encoder.encode(o) },
50
- lambda { |s| Yajl::Parser.parse(s) }
52
+ lambda { |s| Yajl::Parser.parse(s) },
53
+ lambda { ::Yajl::ParseError }
51
54
  ]
52
55
 
53
56
  # The "raise an exception because there's no backend" backend
54
57
  #
55
- NONE = [ lambda { |s| raise 'no JSON backend found' } ] * 2
58
+ NONE = [
59
+ lambda { |s| raise 'no JSON backend found' },
60
+ lambda { |s| raise 'no JSON backend found' },
61
+ lambda { raise 'no JSON backend found' }
62
+ ]
56
63
 
57
64
  # [Re-]Attempts to detect a JSON backend
58
65
  #
@@ -110,7 +117,13 @@ module Json
110
117
  #
111
118
  def self.decode (s)
112
119
 
113
- @backend[1].call(s)
120
+ begin
121
+
122
+ @backend[1].call(s)
123
+
124
+ rescue @backend[2].call => e
125
+ raise ParserError, e.message
126
+ end
114
127
  end
115
128
 
116
129
  # Duplicates an object by turning it into JSON and back.
@@ -121,6 +134,10 @@ module Json
121
134
 
122
135
  (@backend == NONE) ? Marshal.load(Marshal.dump(o)) : decode(encode(o))
123
136
  end
137
+
138
+ # Wraps parser errors during decode
139
+ #
140
+ class ParserError < StandardError; end
124
141
  end
125
142
  end
126
143
 
data/rufus-json.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rufus-json}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["John Mettraux"]
12
- s.date = %q{2010-05-03}
11
+ s.authors = ["John Mettraux", "Torsten Schoenebaum"]
12
+ s.date = %q{2010-05-26}
13
13
  s.description = %q{
14
14
  One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, active_support). Has a preference for yajl.
15
15
  }
@@ -48,18 +48,24 @@ One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, acti
48
48
  s.add_development_dependency(%q<json>, [">= 0"])
49
49
  s.add_development_dependency(%q<yajl-ruby>, [">= 0"])
50
50
  s.add_development_dependency(%q<activesupport>, [">= 0"])
51
+ s.add_development_dependency(%q<rake>, [">= 0"])
51
52
  s.add_development_dependency(%q<yard>, [">= 0"])
53
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
52
54
  else
53
55
  s.add_dependency(%q<json>, [">= 0"])
54
56
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
55
57
  s.add_dependency(%q<activesupport>, [">= 0"])
58
+ s.add_dependency(%q<rake>, [">= 0"])
56
59
  s.add_dependency(%q<yard>, [">= 0"])
60
+ s.add_dependency(%q<jeweler>, [">= 0"])
57
61
  end
58
62
  else
59
63
  s.add_dependency(%q<json>, [">= 0"])
60
64
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
61
65
  s.add_dependency(%q<activesupport>, [">= 0"])
66
+ s.add_dependency(%q<rake>, [">= 0"])
62
67
  s.add_dependency(%q<yard>, [">= 0"])
68
+ s.add_dependency(%q<jeweler>, [">= 0"])
63
69
  end
64
70
  end
65
71
 
data/test/test.rb CHANGED
@@ -66,6 +66,11 @@ class JsonTest < Test::Unit::TestCase
66
66
  do_test_deep_nesting('json', Rufus::Json::JSON)
67
67
  end
68
68
 
69
+ def test_parser_error_json
70
+
71
+ do_test_parser_error('json', Rufus::Json::JSON)
72
+ end
73
+
69
74
  def test_decode_yajl
70
75
 
71
76
  do_test_decode('yajl', Rufus::Json::YAJL)
@@ -86,6 +91,11 @@ class JsonTest < Test::Unit::TestCase
86
91
  do_test_deep_nesting('yajl', Rufus::Json::YAJL)
87
92
  end
88
93
 
94
+ def test_parser_error_yajl
95
+
96
+ do_test_parser_error('yajl', Rufus::Json::YAJL)
97
+ end
98
+
89
99
  def test_decode_as
90
100
 
91
101
  do_test_decode('active_support', Rufus::Json::ACTIVE)
@@ -162,5 +172,17 @@ class JsonTest < Test::Unit::TestCase
162
172
  assert_equal(s, Rufus::Json.encode(h))
163
173
  assert_equal(h, Rufus::Json.decode(s))
164
174
  end
175
+
176
+ def do_test_parser_error (lib, cons)
177
+
178
+ require lib
179
+ Rufus::Json.backend = cons
180
+
181
+ s = '{foo:cx1234}'
182
+
183
+ assert_raise Rufus::Json::ParserError do
184
+ Rufus::Json.decode(s)
185
+ end
186
+ end
165
187
  end
166
188
 
metadata CHANGED
@@ -5,16 +5,17 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mettraux
13
+ - Torsten Schoenebaum
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-03 00:00:00 +09:00
18
+ date: 2010-05-26 00:00:00 +09:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -54,7 +55,7 @@ dependencies:
54
55
  type: :development
55
56
  version_requirements: *id003
56
57
  - !ruby/object:Gem::Dependency
57
- name: yard
58
+ name: rake
58
59
  prerelease: false
59
60
  requirement: &id004 !ruby/object:Gem::Requirement
60
61
  requirements:
@@ -65,6 +66,30 @@ dependencies:
65
66
  version: "0"
66
67
  type: :development
67
68
  version_requirements: *id004
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ prerelease: false
72
+ requirement: &id005 !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id005
81
+ - !ruby/object:Gem::Dependency
82
+ name: jeweler
83
+ prerelease: false
84
+ requirement: &id006 !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id006
68
93
  description: "\n\
69
94
  One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, active_support). Has a preference for yajl.\n "
70
95
  email: jmettraux@gmail.com