pump 0.1.0 → 0.2.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/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'}, :never_blank => true},
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'}, :never_blank => true, :skip_encoding => true},
28
- {:"created-at" => :created_at, :typecast => :xmlschema, :attributes => {:type => 'datetime'}, :never_blank => true, :skip_encoding => true},
29
- {:name => :name, :never_blank => true}
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
@@ -1,3 +1,3 @@
1
1
  module Pump
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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[:never_blank]
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};''}#{nil_attribute}\#{#{value_and_close_tag_with_blank_check}}#{condition_end}"
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 value_and_close_tag_with_blank_check
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
@@ -18,7 +18,7 @@ module Pump
18
18
  def cast
19
19
  if options[:typecast]
20
20
  ".#{options[:typecast]}"
21
- elsif !options[:skip_encoding]
21
+ elsif !options[:xmlsafe]
22
22
  '.to_s.encode(:xml => :text)'
23
23
  end
24
24
  end
@@ -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 :skip_encoding => true" do
21
- subject { Pump::Xml::Value.new("method_name", {}, [], :skip_encoding => true) }
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
@@ -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
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.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: