jsonbuilder 0.2.2 → 0.2.3

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.
@@ -25,6 +25,8 @@ module Builder
25
25
  def target!
26
26
  if @include_root || @target.is_a?(Array)
27
27
  @target
28
+ elsif @root.nil?
29
+ @target
28
30
  else
29
31
  @target[@root]
30
32
  end
@@ -48,7 +50,11 @@ module Builder
48
50
  if @array_mode
49
51
  @target.current << _target
50
52
  elsif _target.is_a?(Hash)
51
- @target.current.merge!(_target)
53
+ if @target.current.nil?
54
+ @target.merge!(_target)
55
+ else
56
+ @target.current.merge!(_target)
57
+ end
52
58
  else
53
59
  @target.current = _target
54
60
  end
@@ -89,7 +95,7 @@ module Builder
89
95
 
90
96
  def _set_args(args, &block)
91
97
  args.each do |arg|
92
- case arg
98
+ case arg
93
99
  when Hash
94
100
  self << arg.stackable
95
101
  else
@@ -2,7 +2,7 @@ module JsonBuilder
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- REVISION = 2
5
+ REVISION = 3
6
6
  class << self
7
7
  def to_version
8
8
  "#{MAJOR}.#{MINOR}.#{REVISION}"
@@ -20,4 +20,4 @@ require 'builder/xml_markup'
20
20
  require 'builder/hash_structure'
21
21
  require 'builder/json_format'
22
22
  require 'ext/stackable_hash'
23
- require 'ext/stackable_array'
23
+ require 'ext/stackable_array'
@@ -295,4 +295,17 @@ describe Builder::HashStructure, "#array_mode" do
295
295
  }
296
296
  end
297
297
 
298
+ it "should support root! with attributes" do
299
+ builder = Builder::HashStructure.new
300
+ builder.items do
301
+ builder.array_mode do
302
+ _builder = builder.class.new
303
+ builder << _builder.root!(:item, :id => 1) do
304
+ _builder.text 'hello'
305
+ end
306
+ end
307
+ end
308
+ builder.target!.should == [{:item => {:text => "hello", :id => 1}}]
309
+ end
310
+
298
311
  end
@@ -51,6 +51,17 @@ describe Builder::HashStructure, "#<<" do
51
51
  builder.target!.should == {:tags => "value"}
52
52
  end
53
53
 
54
+ it "should merge without any tags" do
55
+ builder = Builder::HashStructure.new
56
+ sub_builder = Builder::HashStructure.new
57
+ sub_builder.item do
58
+ sub_builder.text "hello"
59
+ end
60
+
61
+ builder << sub_builder.target!
62
+ builder.target!.should == {:text => "hello"}
63
+ end
64
+
54
65
  it "should merge its argument into current target" do
55
66
  builder = Builder::HashStructure.new
56
67
  sub_builder = Builder::HashStructure.new
@@ -256,4 +267,4 @@ describe Builder::HashStructure, "#_explore_key_and_args" do
256
267
  builder.target!.should == {:tag => nil}
257
268
  end
258
269
 
259
- end
270
+ end
@@ -35,7 +35,7 @@ describe Builder::JsonFormat do
35
35
  builder << TestObject.new("Recursive Json!").to_json
36
36
  end
37
37
 
38
- builder.to_s.should == '{"text": "Recursive Json!"}'
38
+ builder.to_s.should == '{"text":"Recursive Json!"}'
39
39
  end
40
40
 
41
41
  it 'should not double escape unicode strings inserts when supporting recursive calls' do
@@ -44,7 +44,7 @@ describe Builder::JsonFormat do
44
44
  builder << TestObject.new("テスト").to_json
45
45
  end
46
46
 
47
- builder.to_s.should == '{"text": "\u30c6\u30b9\u30c8"}'
47
+ builder.to_s.should == '{"text":"\u30c6\u30b9\u30c8"}'
48
48
  end
49
49
 
50
50
 
@@ -67,7 +67,7 @@ describe Builder::JsonFormat do
67
67
  end
68
68
  end
69
69
 
70
- builder.to_s.should == "{\"texts\": [\"my text\"]}"
70
+ builder.to_s.should == "{\"texts\":[\"my text\"]}"
71
71
  end
72
72
 
73
73
  it 'should allow string inserts to support recursive calls in array mode' do
@@ -97,7 +97,7 @@ describe Builder::JsonFormat, "#target!" do
97
97
  builder.item("value")
98
98
  end
99
99
  builder.target!.should be_a(Hash)
100
- builder.to_s.should =="{\"item\": \"value\"}"
100
+ builder.to_s.should =="{\"item\":\"value\"}"
101
101
  end
102
102
 
103
103
  it "should return a Hash object when include_root is true" do
@@ -107,7 +107,7 @@ describe Builder::JsonFormat, "#target!" do
107
107
  builder.tag "value"
108
108
  end
109
109
  builder.target!.should be_a(Hash)
110
- builder.to_s.should == '{"root": {"tag": "value"}}'
110
+ builder.to_s.should == '{"root":{"tag":"value"}}'
111
111
  end
112
112
 
113
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-28 00:00:00 +09:00
12
+ date: 2009-10-07 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -35,29 +35,26 @@ files:
35
35
  - README
36
36
  - ChangeLog
37
37
  - Rakefile
38
- - spec/builder
39
38
  - spec/builder/array_mode_spec.rb
40
39
  - spec/builder/hash_structure_spec.rb
41
40
  - spec/builder/json_format_spec.rb
42
41
  - spec/builder/xml_markup_spec.rb
43
- - spec/ext
44
42
  - spec/ext/stackable_array_spec.rb
45
43
  - spec/ext/stackable_hash_spec.rb
46
44
  - spec/jsonbuilder_spec.rb
47
45
  - spec/spec_helper.rb
48
- - lib/builder
49
46
  - lib/builder/abstract.rb
50
47
  - lib/builder/hash_structure.rb
51
48
  - lib/builder/json_format.rb
52
49
  - lib/builder/xml_markup.rb
53
- - lib/ext
54
50
  - lib/ext/stackable_array.rb
55
51
  - lib/ext/stackable_hash.rb
56
52
  - lib/jsonbuilder.rb
57
- - lib/patch
58
53
  - lib/patch/active_support_json_decode.rb
59
54
  has_rdoc: true
60
55
  homepage: http://jsonbuilder.rubyforge.org
56
+ licenses: []
57
+
61
58
  post_install_message:
62
59
  rdoc_options:
63
60
  - --title
@@ -89,9 +86,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
86
  requirements: []
90
87
 
91
88
  rubyforge_project: jsonbuilder
92
- rubygems_version: 1.3.1
89
+ rubygems_version: 1.3.5
93
90
  signing_key:
94
- specification_version: 2
91
+ specification_version: 3
95
92
  summary: Builder::XmlMarkup like JsonBuilder
96
93
  test_files:
97
94
  - spec/jsonbuilder_spec.rb