xml-smart 0.3.18 → 0.3.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 811c9bcaf859068540db8993295edf9b5687b8b9
4
- data.tar.gz: 2211073f067c264599e7aa7a2ed4ac2abc8ae25a
3
+ metadata.gz: fa51f760d8fce09fc7eddfbaf80d4069ab53b8c8
4
+ data.tar.gz: 115c09067901a541d4842d8fbc4489cc955511e3
5
5
  SHA512:
6
- metadata.gz: fb1ed71badd8282dcb6dd48f26ab1a4d76bd06f4b46307be1f19cb1454dfc14699caada083dfd9b1bcd115ef698c81e3e6e7665688c768594b46ae67f81dfd4f
7
- data.tar.gz: 41a91a6914488065fde7d33bb92447bc5d6b045ab753b3edcbec40ed959a932fad37610e003b1dfd7e327f85637dc831b3faf55677f4acfedd1aeaf0f15140aa
6
+ metadata.gz: 67e997065396f2fe48e9005dff78c60a8389020a52143da2d67413ba073400900f9699584aa69dc83f17df699a255d22b7a52a4c8f0edda21694254494064548
7
+ data.tar.gz: 22d951fb421146f9688743a50959dc114e49735ccd57e822ad106f9188f9392c29385bf9472d767281d798f1edb4d2e9a18d1feb0f1d413b51a84bc133d2e7a9
data/lib/xml/smart.rb CHANGED
@@ -34,9 +34,8 @@ module Nokogiri
34
34
  def basepath
35
35
  @basepath || ''
36
36
  end
37
-
37
+
38
38
  def xpath_fast(path)
39
- ns = self.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes)
40
39
  ctx = XPathContext.new(self)
41
40
  ctx.register_namespaces(self.document.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes))
42
41
  path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?
@@ -47,13 +46,13 @@ module Nokogiri
47
46
  result = {}
48
47
  nsall = {}
49
48
  nsde = {}
50
-
51
- self.xpath('//namespace::*').each do |n|
49
+
50
+ self.xpath('//namespace::*').each do |n|
52
51
  unless n.prefix == 'xml'
53
52
  nsde[n.href] = n.prefix if n.prefix.nil?
54
53
  nsall[n.href] = n.prefix
55
54
  end
56
- end
55
+ end
57
56
 
58
57
  count = -1
59
58
  nsall.each do |k,v|
@@ -68,6 +67,7 @@ module Nokogiri
68
67
  @custom_namespace_prefixes = result
69
68
  end
70
69
  def custom_namespace_prefixes
70
+ @custom_namespace_prefixes ||= nil
71
71
  @custom_namespace_prefixes || custom_namespace_prefixes_update
72
72
  end
73
73
  def user_custom_namespace_prefixes
@@ -86,7 +86,6 @@ module Nokogiri
86
86
  # return xpath(path,self.document.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes))
87
87
  return NodeSet.new(document) unless document
88
88
 
89
- ns = self.document.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes)
90
89
  ctx = XPathContext.new(self)
91
90
  ctx.register_namespaces(self.document.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes))
92
91
  path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?
@@ -101,7 +100,7 @@ module Nokogiri
101
100
  name = ele.attributes['href'].value
102
101
  name = path + name if name !~ /^(https?:|ftp:|\/)/
103
102
  content = open(name,{ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read
104
- insert = begin
103
+ insert = begin
105
104
  Nokogiri::XML::parse(content).root # {|config| config.noblanks.noent.strict }.root
106
105
  rescue
107
106
  content
@@ -159,18 +158,18 @@ module XML
159
158
  raise Error, 'a block is mandatory' unless block_given?
160
159
  dom = io = nil
161
160
  begin
162
- if name.is_a?(String) && File.exists?(name)
161
+ if name.is_a?(String) && File.exist?(name)
163
162
  MUTEX.synchronize do
164
163
  io = ::Kernel::open(name,'r+')
165
164
  io.flock(File::LOCK_EX)
166
- end
165
+ end
167
166
  dom = Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }, name
168
167
  io.rewind
169
- elsif name.is_a?(String) && !File.exists?(name)
168
+ elsif name.is_a?(String) && !File.exist?(name)
170
169
  MUTEX.synchronize do
171
170
  io = ::Kernel::open(name,'w')
172
171
  io.flock(File::LOCK_EX)
173
- end
172
+ end
174
173
  dom = Smart::string(default,name)
175
174
  elsif name.is_a?(IO) || name.is_a?(Tempfile)
176
175
  MUTEX.synchronize do
@@ -203,7 +202,7 @@ module XML
203
202
  if dom && block_given?
204
203
  yield dom
205
204
  nil
206
- else
205
+ else
207
206
  dom
208
207
  end
209
208
  end
@@ -213,9 +212,9 @@ module XML
213
212
  raise Error, 'second parameter has to be an xml string' unless default.is_a?(String) || default.nil?
214
213
  dom = begin
215
214
  filename = nil
216
- io = if name.is_a?(String)
215
+ io = if name.is_a?(String)
217
216
  filename = name
218
- ::Kernel::open(name)
217
+ ::Kernel::open(name)
219
218
  else
220
219
  filename = name.path
221
220
  name
@@ -237,7 +236,7 @@ module XML
237
236
  if block_given?
238
237
  yield dom
239
238
  nil
240
- else
239
+ else
241
240
  dom
242
241
  end
243
242
  end
@@ -248,7 +247,7 @@ module XML
248
247
  if block_given?
249
248
  yield dom
250
249
  nil
251
- else
250
+ else
252
251
  dom
253
252
  end
254
253
  end
@@ -87,7 +87,6 @@ module XML
87
87
  tnos = nos.map{|e|e.dup}
88
88
  nos = Nokogiri::XML::NodeSet.new(nos.first.document,tnos)
89
89
  end
90
- return [Nokogiri::XML::NodeSet.new(nos.first.document,tnos), true]
91
90
  return [nos, !same]
92
91
  else
93
92
  return [nos, false]
@@ -216,7 +215,7 @@ module XML
216
215
  def to_doc
217
216
  doc = Nokogiri::XML::Document.new
218
217
  doc.root = @element
219
- dom = Dom.new(doc)
218
+ Dom.new(doc)
220
219
  end
221
220
  end
222
221
 
@@ -22,16 +22,16 @@ module XML
22
22
  name = name.to_s unless name.nil?
23
23
  name = nil if name =~ /^xmlns\d*$/
24
24
  nd = @node.namespace_definitions.find{|n| n.prefix == name}
25
- (name.respond_to?(:to_s) || name.nil?) && nd ? Namespace.new(nd) : nil;
26
- end
25
+ (name.respond_to?(:to_s) || name.nil?) && nd ? Namespace.new(nd) : nil;
26
+ end
27
27
  end
28
- def []=(name,value)
28
+ def []=(name,value)
29
29
  name = nil if name == 'xmlns'
30
30
  self.add(name,value)
31
31
  end
32
32
 
33
33
  def add(name,value)
34
- if (name.respond_to?(:to_s) || name.nil?) && value.respond_to?(:to_s)
34
+ if (name.respond_to?(:to_s) || name.nil?) && value.respond_to?(:to_s)
35
35
  nnod = Nokogiri::XML::Node.new(@node.name,@node.document)
36
36
  nnew = Element.new(nnod)
37
37
  nold = Element.new(@node)
@@ -39,17 +39,17 @@ module XML
39
39
  nnew.attributes[attr.qname.name] = attr.value
40
40
  end
41
41
  ns = nnod.add_namespace_definition(name.nil? ? nil : name.to_s,value.to_s)
42
- @node.namespace_definitions.each do |ns|
43
- nnod.add_namespace_definition(ns.prefix,ns.href)
42
+ @node.namespace_definitions.each do |nst|
43
+ nnod.add_namespace_definition(nst.prefix,nst.href)
44
44
  end
45
45
  nnew.add(nold.children)
46
46
  nold.replace_by(nnew)
47
47
  @node = nnod
48
- @parent.instance_variable_set(:@element,@node)
48
+ @parent.instance_variable_set(:@element,@node)
49
49
  @node.document.custom_namespace_prefixes_update
50
50
  @node.document.ns_update
51
51
  Namespace.new(ns)
52
- end
52
+ end
53
53
  end
54
54
 
55
55
  def length; @node.namespace_definitions.length; end
@@ -109,7 +109,7 @@ module XML
109
109
  nold.attributes.each do |attr|
110
110
  nnew.attributes[attr.qname.name] = attr.value
111
111
  end
112
- @node.namespace_definitions.each do |ns|
112
+ @node.namespace_definitions.each do |ns|
113
113
  nnod.add_namespace_definition(ns.prefix,ns.href) unless block.call(Dom::smart_helper(ns))
114
114
  end
115
115
  nnew.add(nold.children)
@@ -120,8 +120,8 @@ module XML
120
120
  @node.document.ns_update
121
121
  self
122
122
  end
123
- end
124
-
123
+ end
124
+
125
125
  end
126
- end
127
- end
126
+ end
127
+ end
data/test/EXAMPLE.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <test xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xml:lang="de">
2
2
  <names>
3
- <name team="0" a="3">2015-07-28 00:28:53 +0200</name>
3
+ <name team="0" a="3">2016-08-09 15:37:16 +0200</name>
4
4
  <name team="1">Jürgen</name>
5
5
  <name team="1">Michel</name>
6
6
  <name team="1">Raphi</name>
data/test/tc_basic.rb CHANGED
@@ -44,8 +44,8 @@ class TestBasic < MiniTest::Test
44
44
 
45
45
  tmp = doc.find("/test/names/test_node")[3].dump
46
46
  assert(tmp == "<test_node second=\"a\" attr=\"14\"/>" || tmp == "<test_node attr=\"14\" second=\"a\"/>")
47
-
48
- nodes = doc.find("/test/names/test_node")
47
+
48
+ nodes = doc.find("/test/names/test_node")
49
49
  assert(nodes.length == 9)
50
50
  assert(nodes.empty? == false)
51
51
  assert(nodes.delete_all! == true)
@@ -57,10 +57,10 @@ class TestBasic < MiniTest::Test
57
57
  count = 0
58
58
  nodes = doc.find("/test/colors/*")
59
59
  assert(nodes.length == 3)
60
- nodes.delete_if do |node|
60
+ nodes.delete_if do |tnode|
61
61
  count += 1
62
62
  count % 2 == 0
63
- end
63
+ end
64
64
  assert(nodes.length == 2)
65
65
  assert(doc.find("/test/colors/*")[0].dump == "<blue taint=\"true\">Yeah</blue>")
66
66
  assert(doc.find("/test/colors/*")[1].dump == "<green taint=\"true\"/>")
@@ -19,16 +19,16 @@ class TestConcurrent < Minitest::Test
19
19
  p[i] = Thread.new do
20
20
  XML::Smart.modify(::File.dirname(__FILE__) + "/concurrent.xml","<solutions/>") do |xml|
21
21
  xml.unformated = true
22
- res = xml.find("/solutions/solution[@matnr=\"#{e_matnr}\" or @secid=\"#{e_secid}\"]").delete_all! if exam
22
+ xml.find("/solutions/solution[@matnr=\"#{e_matnr}\" or @secid=\"#{e_secid}\"]").delete_all! if exam
23
23
  node = xml.root.add("solution",{:matnr => e_matnr, :name => e_name, :secid => e_secid, :assessment => id})
24
24
  1.upto(3) do |qbi|
25
25
  qid = qbi*2
26
- ques = node.add("question", :block => qbi, :question => qid)
26
+ node.add("question", :block => qbi, :question => qid)
27
27
  end
28
28
 
29
- result = xml.to_s
30
- end
31
- end
29
+ result = xml.to_s
30
+ end
31
+ end
32
32
  end
33
33
 
34
34
  p.each do |t|
@@ -52,19 +52,19 @@ class TestConcurrent < Minitest::Test
52
52
  0.upto(nums) do |i|
53
53
  p[i] = Thread.new do
54
54
  XML::Smart.modify(::File.dirname(__FILE__) + "/concurrent.xml","<solutions/>") do |xml|
55
- res = xml.find("/solutions/solution[@matnr=\"#{e_matnr}\" or @secid=\"#{e_secid}\"]").delete_all! if exam
55
+ xml.find("/solutions/solution[@matnr=\"#{e_matnr}\" or @secid=\"#{e_secid}\"]").delete_all! if exam
56
56
  node = xml.root.add("solution",{:matnr => e_matnr, :name => e_name, :secid => e_secid, :when => Time.now.xmlschema, :assessment => id})
57
57
  1.upto(3) do |qbi|
58
58
  qid = qbi*2
59
- ques = node.add("question", :block => qbi, :question => qid)
59
+ node.add("question", :block => qbi, :question => qid)
60
60
  end
61
- end
62
- end
61
+ end
62
+ end
63
63
  end
64
64
 
65
65
  p.each do |t|
66
66
  t.join
67
- end
67
+ end
68
68
  Minitest::PerformanceReporter::end_timing
69
69
  end
70
70
  end
data/test/tc_create.rb CHANGED
@@ -8,19 +8,19 @@ class TestCreate < Minitest::Test
8
8
  #
9
9
  # XML::Smart.modify(FILE,STRING) {} ... create file if !exists?
10
10
  # XML::Smart.modify(FILE) {} ... just open file change and write back (LOCKTIMEOUT defaults to 7)
11
-
11
+
12
12
  File.unlink ::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml" rescue nil
13
13
  t1 = Thread.new do
14
14
  XML::Smart.modify(::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml","<elements/>") { |doc|
15
- node = doc.root.add("element","Thread 1")
15
+ doc.root.add("element","Thread 1")
16
16
  sleep 1
17
17
  }
18
18
  end
19
19
  t2 = Thread.new do
20
20
  sleep 0.5
21
21
  XML::Smart.modify(::File.dirname(__FILE__) + "/EXAMPLE.tmp.xml","<elements/>") { |doc|
22
- node = doc.root.add("element","Thread 2")
23
- }
22
+ doc.root.add("element","Thread 2")
23
+ }
24
24
  end
25
25
  t1.join
26
26
  t2.join
data/test/tc_nested.rb CHANGED
@@ -12,8 +12,8 @@ class TestNested < Minitest::Test
12
12
  soc.find("/root/node").each do |ele|
13
13
  ts = ele.find('text')
14
14
  if ts.any?
15
- a = ts.first.to_doc
16
- end
15
+ ts.first.to_doc
16
+ end
17
17
  end
18
18
  ts = soc.find("/root/node").first
19
19
  ts.add('text','Haller')
data/xml-smart.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xml-smart"
3
- s.version = "0.3.18"
3
+ s.version = "0.3.19"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3"
6
6
  s.summary = "An xml library that doesn't suck - since 2004."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-smart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.18
4
+ version: 0.3.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -163,52 +163,52 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  requirements: []
165
165
  rubyforge_project:
166
- rubygems_version: 2.4.5
166
+ rubygems_version: 2.5.1
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: An xml library that doesn't suck - since 2004.
170
170
  test_files:
171
- - test/tc_xpath_attrs.rb
172
- - test/tc_pi.rb
173
- - test/tc_add.rb
174
- - test/tc_relaxng.rb
171
+ - test/tc_qname.rb
175
172
  - test/tc_delete.rb
176
- - test/tc_copy.rb
177
- - test/tc_string.rb
178
- - test/tc_sort.rb
179
- - test/tc_create.rb
173
+ - test/tc_root.rb
174
+ - test/tc_xinclude.rb
175
+ - test/tc_write.rb
180
176
  - test/tc_namespace_find.rb
181
- - test/tc_xsl.rb
177
+ - test/tc_sort.rb
182
178
  - test/tc_nested.rb
183
- - test/tc_todoc.rb
184
- - test/tc_move_elements.rb
179
+ - test/tc_xmlschema.rb
180
+ - test/tc_xpath_attrs.rb
185
181
  - test/tc_namespace_default.rb
186
- - test/tc_root.rb
187
- - test/tc_xpath_functions.rb
182
+ - test/tc_version.rb
188
183
  - test/tc_set_or_replace.rb
184
+ - test/tc_string.rb
185
+ - test/tc_xsl.rb
189
186
  - test/tc_concurrent.rb
190
- - test/tc_xmlschema.rb
191
- - test/tc_qname.rb
192
- - test/tc_write.rb
193
- - test/tc_xinclude.rb
194
- - test/tc_basic.rb
195
- - test/tc_xpath.rb
196
- - test/tc_version.rb
197
187
  - test/tc_xpath_root.rb
198
188
  - test/tc_namespace_detailed.rb
189
+ - test/tc_copy.rb
190
+ - test/tc_basic.rb
191
+ - test/tc_move_elements.rb
192
+ - test/tc_create.rb
193
+ - test/tc_xpath.rb
194
+ - test/tc_relaxng.rb
195
+ - test/tc_xpath_functions.rb
196
+ - test/tc_pi.rb
197
+ - test/tc_add.rb
198
+ - test/tc_todoc.rb
199
+ - test/HELLO.xml
200
+ - test/EXAMPLE-NS.xml
201
+ - test/3.xml
199
202
  - test/XSL_BASE.xml
200
- - test/EXAMPLE.tmp.xml
201
203
  - test/1.xml
202
- - test/2.xml
203
- - test/EXAMPLE-NSE.xml
204
- - test/XSL_DOCUMENT.xml
205
- - test/3.xml
206
204
  - test/EXAMPLE.str.xml
207
- - test/HELLO-MORE.xml
205
+ - test/2.xml
208
206
  - test/EXAMPLE.xml
207
+ - test/EXAMPLE-NSE.xml
209
208
  - test/concurrent.xml
210
- - test/EXAMPLE-NS.xml
211
- - test/HELLO.xml
209
+ - test/HELLO-MORE.xml
210
+ - test/XSL_DOCUMENT.xml
211
+ - test/EXAMPLE.tmp.xml
212
212
  - test/HELLO.rng
213
213
  - test/HELLO.xsd
214
214
  - test/smartrunner.rb