rufus-json 0.2.4 → 0.2.5

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/CHANGELOG.txt CHANGED
@@ -2,6 +2,12 @@
2
2
  = rufus-json CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-json - 0.2.5 released 2010/08/10
6
+
7
+ - Rufus::Json.encode(o) now accepting string, numbers, boolean and null
8
+ for any JSON backend (especially json and json-pure)
9
+
10
+
5
11
  == rufus-json - 0.2.4 released 2010/07/17
6
12
 
7
13
  - Rufus::Json.pretty_encode(o) (except for active_support)
data/lib/rufus/json.rb CHANGED
@@ -26,14 +26,18 @@
26
26
  module Rufus
27
27
  module Json
28
28
 
29
- VERSION = '0.2.4'
29
+ VERSION = '0.2.5'
30
30
 
31
31
  # The JSON / JSON pure decoder
32
32
  #
33
33
  JSON = [
34
34
  lambda { |o, opts|
35
35
  opts[:max_nesting] = false unless opts.has_key?(:max_nesting)
36
- ::JSON.generate(o, opts)
36
+ if o.is_a?(Hash) or o.is_a?(Array)
37
+ ::JSON.generate(o, opts)
38
+ else
39
+ ::JSON.generate([ o ], opts).strip[1..-2]
40
+ end
37
41
  },
38
42
  lambda { |s| ::JSON.parse("[#{s}]", :max_nesting => nil).first },
39
43
  lambda { ::JSON::ParserError }
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.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux", "Torsten Schoenebaum"]
12
- s.date = %q{2010-07-17}
12
+ s.date = %q{2010-08-10}
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
  }
data/test/do_test.rb CHANGED
@@ -20,7 +20,7 @@ else
20
20
  end
21
21
 
22
22
  puts
23
- puts ' ' + Rufus::Json.backend.to_s.upcase
23
+ puts " #{Rufus::Json.backend.to_s.upcase} (#{JSON_LIB})"
24
24
  puts
25
25
 
26
26
 
@@ -33,6 +33,7 @@ class DoTest < Test::Unit::TestCase
33
33
 
34
34
  target = JSON_LIB.to_sym
35
35
  target = :active if target == :active_support
36
+ target = :json if JSON_LIB == 'json/pure'
36
37
 
37
38
  assert_equal target, Rufus::Json.backend
38
39
  end
@@ -47,13 +48,24 @@ class DoTest < Test::Unit::TestCase
47
48
  assert_equal "[1,2,3]", Rufus::Json.encode([ 1, 2, 3 ])
48
49
  end
49
50
 
51
+ def test_encode_value # instead of object or array
52
+
53
+ assert_equal 'null', Rufus::Json.encode(nil)
54
+ assert_equal 'true', Rufus::Json.encode(true)
55
+ assert_equal 'false', Rufus::Json.encode(false)
56
+ assert_equal '1.0', Rufus::Json.encode(1.0)
57
+ assert_equal '"Capitaine Haddock"', Rufus::Json.encode('Capitaine Haddock')
58
+ end
59
+
50
60
  def test_dup
51
61
 
52
62
  d0 = { 'id' => 'nada' }
53
63
  d1 = { :id => :nada }
64
+ #d2 = { :id => { :tree => [ 'nada', {}, [] ] } }
54
65
 
55
66
  assert_equal({ 'id' => 'nada' }, Rufus::Json.dup(d0))
56
67
  assert_equal({ 'id' => 'nada' }, Rufus::Json.dup(d1))
68
+ #assert_equal({ 'id' => 'tree' }, Rufus::Json.dup(d2))
57
69
  end
58
70
 
59
71
  def test_deep_nesting
data/test/test.rb CHANGED
@@ -10,7 +10,7 @@ require 'rubygems'
10
10
  R = `which ruby`.strip
11
11
  P = File.dirname(__FILE__)
12
12
 
13
- %w[ json active_support yajl ].each do |lib|
13
+ %w[ json active_support yajl json/pure ].each do |lib|
14
14
  puts
15
15
  puts '-' * 80
16
16
  puts "#{R} #{P}/do_test.rb #{lib}"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 4
9
- version: 0.2.4
8
+ - 5
9
+ version: 0.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mettraux
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-17 00:00:00 +09:00
18
+ date: 2010-08-10 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency