pump 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pump/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pump
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/pump/xml/node.rb CHANGED
@@ -2,7 +2,6 @@ module Pump
2
2
  class Xml
3
3
  class Node
4
4
  attr_reader :name, :attributes, :nodes, :options
5
- attr_writer :level
6
5
 
7
6
  def initialize(name, attributes={}, nodes=[], options={})
8
7
  @name = name
@@ -15,6 +14,11 @@ module Pump
15
14
  def to_s
16
15
  end
17
16
 
17
+ def level=(new_level)
18
+ @level = new_level
19
+ nodes.each{|node| node.level = @level + 1}
20
+ end
21
+
18
22
  private
19
23
 
20
24
  def add_node(node)
data/lib/pump/xml/tag.rb CHANGED
@@ -7,7 +7,9 @@ module Pump
7
7
 
8
8
  def initialize(*args)
9
9
  super
10
- nodes.first.options = options if value_nodes?
10
+ if value_nodes?
11
+ nodes.first.options = options
12
+ end
11
13
  end
12
14
 
13
15
  def to_s
data/lib/pump/xml.rb CHANGED
@@ -38,7 +38,15 @@ module Pump
38
38
 
39
39
  def sub_tags
40
40
  tag_config.map do |config|
41
- tag_name, method_name = config.keys.first, config.values.first
41
+ build_tag(config)
42
+ end
43
+ end
44
+
45
+ def build_tag(config)
46
+ tag_name, method_name = config.keys.first, config.values.first
47
+ if method_name.is_a?(Array)
48
+ Tag.new(tag_name, config[:attributes], method_name.map{|conf| build_tag(conf) }, config)
49
+ else
42
50
  Tag.new(tag_name, config[:attributes], Value.new(method_name), config)
43
51
  end
44
52
  end
@@ -199,5 +199,13 @@ describe Pump::Xml do
199
199
  end
200
200
  end
201
201
  end
202
+
203
+ context "deeper nesting" do
204
+ let(:xml) { Pump::Xml.new('person', [{:name => :name}, {:parent => [{:name => :name}, {:age => :age}]}], :instruct => false) }
205
+
206
+ it "returns xml string" do
207
+ xml.encode(person).should eql("<person>\n <name>Benny</name>\n <parent>\n <name>Benny</name>\n <age>9</age>\n </parent>\n</person>")
208
+ end
209
+ end
202
210
  end
203
211
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: