pump 0.0.5 → 0.1.0
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/lib/pump/version.rb +1 -1
- data/lib/pump/xml/tag.rb +1 -13
- data/lib/pump/xml/tag_array.rb +1 -1
- data/spec/pump/xml/tag_spec.rb +0 -66
- data/spec/pump/xml_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- metadata +2 -2
data/lib/pump/version.rb
CHANGED
data/lib/pump/xml/tag.rb
CHANGED
@@ -44,7 +44,7 @@ module Pump
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def value_and_close_tag_with_blank_check
|
47
|
-
"
|
47
|
+
"v.nil? ? \"/>\n\" : \"#{value_and_close_tag('v')}\""
|
48
48
|
end
|
49
49
|
|
50
50
|
def attributes_string
|
@@ -58,18 +58,6 @@ module Pump
|
|
58
58
|
"\#{\" nil=\\\"true\\\"\" if v.nil?}" if options[:nil_check]
|
59
59
|
end
|
60
60
|
|
61
|
-
def blank_check
|
62
|
-
if respond_to?(:blank?)
|
63
|
-
"v.blank?"
|
64
|
-
else
|
65
|
-
"v.nil? || v == ''"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def close_blank_tag
|
70
|
-
"\"/>\n\""
|
71
|
-
end
|
72
|
-
|
73
61
|
def condition_start
|
74
62
|
"\#{\"" if conditional?
|
75
63
|
end
|
data/lib/pump/xml/tag_array.rb
CHANGED
data/spec/pump/xml/tag_spec.rb
CHANGED
@@ -7,70 +7,4 @@ describe Pump::Xml::Tag do
|
|
7
7
|
lambda{ Pump::Xml::Tag.new(0) }.should_not raise_error
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
11
|
-
describe ".to_s" do
|
12
|
-
context "with value node(s)" do
|
13
|
-
let(:attributes) { {} }
|
14
|
-
let(:options) { {} }
|
15
|
-
subject{ Pump::Xml::Tag.new("tag", attributes, Pump::Xml::Value.new('method'), options).to_s }
|
16
|
-
|
17
|
-
it {should eql(
|
18
|
-
"<tag\#{v = object.method;''}\#{v.nil? || v == '' ? \"/>\n\" : \">\#{v.to_s.encode(:xml => :text)}</tag>\n\"}"
|
19
|
-
)}
|
20
|
-
|
21
|
-
context "with :nil_check => true" do
|
22
|
-
let(:options) { {:nil_check => true} }
|
23
|
-
|
24
|
-
it {should eql(
|
25
|
-
"<tag\#{v = object.method;''}\#{\" nil=\\\"true\\\"\" if v.nil?}\#{v.nil? || v == '' ? \"/>\n\" : \">\#{v.to_s.encode(:xml => :text)}</tag>\n\"}"
|
26
|
-
)}
|
27
|
-
end
|
28
|
-
|
29
|
-
context "with :never_blank => true" do
|
30
|
-
let(:options) { {:never_blank => true} }
|
31
|
-
|
32
|
-
it {should eql(
|
33
|
-
"<tag>\#{object.method.to_s.encode(:xml => :text)}</tag>\n"
|
34
|
-
)}
|
35
|
-
|
36
|
-
context "with attributes" do
|
37
|
-
let(:attributes) { {:foo => "bar"} }
|
38
|
-
|
39
|
-
it {should eql(
|
40
|
-
"<tag foo=\\\"bar\\\">\#{object.method.to_s.encode(:xml => :text)}</tag>\n"
|
41
|
-
)}
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with :skip_encoding => true" do
|
46
|
-
let(:options) { {:skip_encoding => true} }
|
47
|
-
|
48
|
-
it {should eql(
|
49
|
-
"<tag\#{v = object.method;''}\#{v.nil? || v == '' ? \"/>\n\" : \">\#{v}</tag>\n\"}"
|
50
|
-
)}
|
51
|
-
end
|
52
|
-
|
53
|
-
context "with attributes" do
|
54
|
-
let(:attributes) { {:foo => "bar"} }
|
55
|
-
|
56
|
-
it {should eql(
|
57
|
-
"<tag foo=\\\"bar\\\"\#{v = object.method;''}\#{v.nil? || v == '' ? \"/>\n\" : \">\#{v.to_s.encode(:xml => :text)}</tag>\n\"}"
|
58
|
-
)}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "with other tag child nodes" do
|
63
|
-
let(:attributes1) { {} }
|
64
|
-
let(:options1) { {} }
|
65
|
-
let(:attributes2) { {} }
|
66
|
-
let(:options2) { {:never_blank => true, :skip_encoding => true} }
|
67
|
-
let(:tag2) { Pump::Xml::Tag.new("child", attributes2, Pump::Xml::Value.new('method'), options2) }
|
68
|
-
let(:tag1) { Pump::Xml::Tag.new("root", attributes1, [tag2], options1) }
|
69
|
-
subject{ tag1.to_s }
|
70
|
-
|
71
|
-
it {should eql(
|
72
|
-
"<root>\n <child>\#{object.method}</child>\n</root>\n"
|
73
|
-
)}
|
74
|
-
end
|
75
|
-
end
|
76
10
|
end
|
data/spec/pump/xml_spec.rb
CHANGED
@@ -44,7 +44,7 @@ describe Pump::Xml do
|
|
44
44
|
let(:people) { [] }
|
45
45
|
|
46
46
|
it "returns xml string" do
|
47
|
-
xml.encode(people).should eql("#{XML_INSTRUCT}<people type=\"array\"
|
47
|
+
xml.encode(people).should eql("#{XML_INSTRUCT}<people type=\"array\"/>\n")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -53,7 +53,7 @@ describe Pump::Xml do
|
|
53
53
|
let(:people) { [] }
|
54
54
|
|
55
55
|
it "returns xml string" do
|
56
|
-
xml.encode(people).should eql("<people type=\"array\"
|
56
|
+
xml.encode(people).should eql("<people type=\"array\"/>\n")
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -109,7 +109,7 @@ describe Pump::Xml do
|
|
109
109
|
let(:person) { Struct.new(:name, :age).new('', 9) }
|
110
110
|
|
111
111
|
it do
|
112
|
-
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <name
|
112
|
+
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <name></name>\n</person>\n")
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
data/spec/spec_helper.rb
CHANGED
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
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|