pump 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmarks/encode.rb +4 -4
- data/lib/pump/version.rb +1 -1
- data/lib/pump/xml/tag.rb +4 -8
- data/lib/pump/xml/value.rb +1 -1
- data/spec/pump/xml/value_spec.rb +2 -2
- data/spec/pump/xml_spec.rb +2 -10
- metadata +1 -1
data/benchmarks/encode.rb
CHANGED
@@ -18,15 +18,15 @@ end
|
|
18
18
|
# Not optimized pump
|
19
19
|
pump = Pump::Xml.new('person', [
|
20
20
|
{:age => :age, :attributes => {:type => 'integer'}},
|
21
|
-
{:"created-at" => :created_at, :typecast => :xmlschema, :attributes => {:type => 'datetime'}, :
|
21
|
+
{:"created-at" => :created_at, :typecast => :xmlschema, :attributes => {:type => 'datetime'}, :never_nil => true},
|
22
22
|
{:name => :name}
|
23
23
|
])
|
24
24
|
|
25
25
|
# Heavily optimized pump
|
26
26
|
pump_optimized = Pump::Xml.new('person', [
|
27
|
-
{:age => :age, :attributes => {:type => 'integer'}, :
|
28
|
-
{:"created-at" => :created_at, :typecast => :xmlschema, :attributes => {:type => 'datetime'}, :
|
29
|
-
{:name => :name, :
|
27
|
+
{:age => :age, :attributes => {:type => 'integer'}, :never_nil => true, :xmlsafe => true},
|
28
|
+
{:"created-at" => :created_at, :typecast => :xmlschema, :attributes => {:type => 'datetime'}, :never_nil => true, :xmlsafe => true},
|
29
|
+
{:name => :name, :never_nil => true}
|
30
30
|
])
|
31
31
|
|
32
32
|
if defined?(Ox)
|
data/lib/pump/version.rb
CHANGED
data/lib/pump/xml/tag.rb
CHANGED
@@ -13,10 +13,10 @@ module Pump
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_s
|
16
|
-
if !value_nodes? || options[:
|
16
|
+
if !value_nodes? || options[:never_nil]
|
17
17
|
"#{condition_start}#{open_tag}#{value_and_close_tag}#{condition_end}"
|
18
18
|
else
|
19
|
-
"#{condition_start}#{open_tag}\#{v = #{nodes.first.plain};''}
|
19
|
+
"#{condition_start}#{open_tag}\#{v = #{nodes.first.plain};''}\#{#{value_and_close_tag_with_nil_check}}#{condition_end}"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -43,8 +43,8 @@ module Pump
|
|
43
43
|
">#{value}#{tabs unless value_nodes?}</#{name}>\n"
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
"v.nil? ? \"/>\n\" : \"#{value_and_close_tag('v')}\""
|
46
|
+
def value_and_close_tag_with_nil_check
|
47
|
+
"v.nil? ? \" nil=\\\"true\\\"/>\n\" : \"#{value_and_close_tag('v')}\""
|
48
48
|
end
|
49
49
|
|
50
50
|
def attributes_string
|
@@ -54,10 +54,6 @@ module Pump
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def nil_attribute
|
58
|
-
"\#{\" nil=\\\"true\\\"\" if v.nil?}" if options[:nil_check]
|
59
|
-
end
|
60
|
-
|
61
57
|
def condition_start
|
62
58
|
"\#{\"" if conditional?
|
63
59
|
end
|
data/lib/pump/xml/value.rb
CHANGED
data/spec/pump/xml/value_spec.rb
CHANGED
@@ -17,8 +17,8 @@ describe Pump::Xml::Value do
|
|
17
17
|
describe "#to_s" do
|
18
18
|
its(:to_s) { should eql("\#{object.method_name.to_s.encode(:xml => :text)}") }
|
19
19
|
|
20
|
-
context "with option :
|
21
|
-
subject { Pump::Xml::Value.new("method_name", {}, [], :
|
20
|
+
context "with option :xmlsafe => true" do
|
21
|
+
subject { Pump::Xml::Value.new("method_name", {}, [], :xmlsafe => true) }
|
22
22
|
|
23
23
|
its(:to_s) { should eql("\#{object.method_name}") }
|
24
24
|
end
|
data/spec/pump/xml_spec.rb
CHANGED
@@ -117,15 +117,7 @@ describe Pump::Xml do
|
|
117
117
|
let(:person) { Struct.new(:name, :age).new(nil, 9) }
|
118
118
|
|
119
119
|
it do
|
120
|
-
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <name/>\n</person>\n")
|
121
|
-
end
|
122
|
-
|
123
|
-
context "and with :nil_check => true" do
|
124
|
-
let(:xml) { Pump::Xml.new('person', [{:name => :name, :nil_check => true}]) }
|
125
|
-
|
126
|
-
it do
|
127
|
-
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <name nil=\"true\"/>\n</person>\n")
|
128
|
-
end
|
120
|
+
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <name nil=\"true\"/>\n</person>\n")
|
129
121
|
end
|
130
122
|
end
|
131
123
|
|
@@ -166,7 +158,7 @@ describe Pump::Xml do
|
|
166
158
|
let(:person) { Struct.new(:at).new(nil) }
|
167
159
|
|
168
160
|
it "returns xml string" do
|
169
|
-
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <at type=\"datetime\"/>\n</person>\n")
|
161
|
+
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <at type=\"datetime\" nil=\"true\"/>\n</person>\n")
|
170
162
|
end
|
171
163
|
end
|
172
164
|
end
|