xml-smart 0.3.6 → 0.3.7

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/xml/smart.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'nokogiri'
3
- require 'lockfile'
4
3
  require 'tempfile'
5
4
 
6
5
  require File.expand_path(File.dirname(__FILE__) + '/smart_qname')
@@ -112,12 +111,7 @@ module XML
112
111
  module Smart
113
112
  VERSION = File.read(File.expand_path(File.dirname(__FILE__) + '/../../xml-smart.gemspec')).match(/\.version\s*=[^\n]+?([\d\.]+)[^\n]+\n/)[1]
114
113
  LIBXML_VERSION = Nokogiri::VERSION_INFO['libxml']['loaded']
115
- LOCKFILE = {
116
- :min_sleep => 0.25,
117
- :max_sleep => 5,
118
- :sleep_inc => 0.25,
119
- :max_age => 5
120
- }
114
+ MUTEX = Mutex.new
121
115
  COPY = 0
122
116
  MOVE = 1
123
117
 
@@ -126,15 +120,35 @@ module XML
126
120
  def self::modify(name,default=nil,&block)
127
121
  raise Error, 'first parameter has to be a filename or filehandle' unless name.is_a?(String) || name.is_a?(IO) || name.is_a?(Tempfile)
128
122
  raise Error, 'a block is mandatory' unless block_given?
129
- lfname = name.is_a?(String) ? name : name.fileno.to_s
130
- lockfile = Lockfile.new(lfname + '.lock',LOCKFILE)
123
+ dom = io = nil
131
124
  begin
132
- lockfile.lock
133
- so = Smart::open_unprotected(name,default)
134
- block.call(so)
135
- so.save_as(name)
125
+ if name.is_a?(String) && File.exists?(name)
126
+ MUTEX.synchronize do
127
+ io = ::Kernel::open(name,'r+')
128
+ io.flock(File::LOCK_EX)
129
+ end
130
+ dom = Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }
131
+ io.rewind
132
+ elsif name.is_a?(String) && !File.exists?(name)
133
+ MUTEX.synchronize do
134
+ io = ::Kernel::open(name,'w')
135
+ io.flock(File::LOCK_EX)
136
+ end
137
+ dom = Smart::string(default)
138
+ elsif name.is_a?(IO) || name.is_a?(Tempfile)
139
+ MUTEX.synchronize do
140
+ io = name
141
+ io.flock(File::LOCK_EX)
142
+ end
143
+ dom = Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }
144
+ end
145
+ block.call(dom)
146
+ dom.save_as(io)
147
+ rescue => e
148
+ puts e.message
149
+ raise Error, "could not open #{name}"
136
150
  ensure
137
- lockfile.unlock
151
+ io.flock(File::LOCK_UN) if io
138
152
  end
139
153
  nil
140
154
  end
@@ -142,15 +156,7 @@ module XML
142
156
  def self::open(name,default=nil)
143
157
  raise Error, 'first parameter has to be a filename or filehandle' unless name.is_a?(String) || name.is_a?(IO) || name.is_a?(Tempfile)
144
158
  raise Error, 'second parameter has to be an xml string' unless default.is_a?(String) || default.nil?
145
- lfname = name.is_a?(String) ? name : name.fileno.to_s
146
- lockfile = Lockfile.new(lfname + '.lock',LOCKFILE)
147
- dom = nil
148
- begin
149
- lockfile.lock
150
- dom = Smart::open_unprotected(name,default)
151
- ensure
152
- lockfile.unlock
153
- end
159
+ dom = Smart::open_unprotected(name,default,true)
154
160
  if dom && block_given?
155
161
  yield dom
156
162
  nil
@@ -159,14 +165,20 @@ module XML
159
165
  end
160
166
  end
161
167
 
162
- def self::open_unprotected(name,default=nil)
168
+ def self::open_unprotected(name,default=nil,lock=false)
163
169
  raise Error, 'first parameter has to be a filename or filehandle' unless name.is_a?(String) || name.is_a?(IO) || name.is_a?(Tempfile)
164
170
  raise Error, 'second parameter has to be an xml string' unless default.is_a?(String) || default.nil?
165
171
  dom = begin
166
- io = name.is_a?(String) ? ::Kernel::open(name) : name
167
- Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }
168
- rescue
172
+ io = name.is_a?(String) ? ::Kernel::open(name) : name
173
+ begin
174
+ io.flock(File::LOCK_EX) if lock
175
+ Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }
176
+ ensure
177
+ io.flock(File::LOCK_UN)
178
+ end
179
+ rescue => e
169
180
  if default.nil?
181
+ puts e.message
170
182
  raise Error, "could not open #{name}"
171
183
  else
172
184
  Smart::string(default)
data/lib/xml/smart_dom.rb CHANGED
@@ -46,7 +46,7 @@ module XML
46
46
  end
47
47
 
48
48
  def save_as(name)
49
- raise Error, 'first parameter has to be a filename or filehandle' unless name.is_a?(String) || name.is_a?(IO)
49
+ raise Error, 'first parameter has to be a filename or filehandle' unless name.is_a?(String) || name.is_a?(IO) || name.is_a?(Tempfile)
50
50
  begin
51
51
  io = name.is_a?(String) ? ::Kernel::open(name,'w') : name
52
52
  rescue
@@ -58,7 +58,7 @@ module XML
58
58
  @dom.root.serialize(:encoding => 'UTF-8', :save_with => Nokogiri::XML::Node::SaveOptions::FORMAT | Nokogiri::XML::Node::SaveOptions::AS_XML)
59
59
  end
60
60
  io.write ftext
61
- io.close
61
+ io.close unless name == io
62
62
  end
63
63
 
64
64
  def save_unformated=(val); @save_unformated = (val.is_a?(TrueClass) ? true : false); 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">2013-07-03 00:34:13 +0200</name>
3
+ <name team="0" a="3">2013-07-31 19:41:52 +0200</name>
4
4
  <name team="1">Jürgen</name>
5
5
  <name team="1">Michel</name>
6
6
  <name team="1">Raphi</name>
@@ -14,4 +14,4 @@
14
14
  <green taint="true"/>
15
15
  </colors>
16
16
  <soap:hallo/>
17
- </test>
17
+ </test>
data/test/concurrent.xml CHANGED
@@ -1 +1,7 @@
1
- <solutions><solution matnr="9906264" name="mangler" secid="1" assessment="16"><question block="1" question="2"/><question block="2" question="4"/><question block="3" question="6"/></solution></solutions>
1
+ <solutions>
2
+ <solution matnr="9906264" name="mangler" secid="1" when="2013-07-31T19:41:48+02:00" assessment="16">
3
+ <question block="1" question="2"/>
4
+ <question block="2" question="4"/>
5
+ <question block="3" question="6"/>
6
+ </solution>
7
+ </solutions>
data/test/tc_pi.rb CHANGED
@@ -16,7 +16,6 @@ class TestPi < MiniTest::Unit::TestCase
16
16
 
17
17
  doc.root.add_before('?xsl-stylesheet', 'a="3" b="7"')
18
18
  doc.root.children.delete_all!
19
- puts doc.to_s
20
19
  assert doc.to_s == "<?xml version=\"1.0\"?>\n<?xsl-stylesheet a=\"3\" b=\"7\"?>\n<test xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xml:lang=\"de\">\n <?tobias vj?>\n</test>\n"
21
20
  end
22
21
  end
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.6"
3
+ s.version = "0.3.7"
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."
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.required_ruby_version = '>=1.9.3'
20
20
 
21
21
  s.add_runtime_dependency 'nokogiri'
22
- s.add_runtime_dependency 'lockfile'
23
22
  s.add_runtime_dependency 'term-ansicolor'
24
23
  s.add_runtime_dependency 'minitest', '=4.7.4'
25
24
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-smart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Juergen eTM Mangler
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-07-02 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: nokogiri
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,20 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: lockfile
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
37
26
  requirements:
38
27
  - - ! '>='
39
28
  - !ruby/object:Gem::Version
@@ -41,6 +30,7 @@ dependencies:
41
30
  - !ruby/object:Gem::Dependency
42
31
  name: term-ansicolor
43
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
44
34
  requirements:
45
35
  - - ! '>='
46
36
  - !ruby/object:Gem::Version
@@ -48,6 +38,7 @@ dependencies:
48
38
  type: :runtime
49
39
  prerelease: false
50
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
51
42
  requirements:
52
43
  - - ! '>='
53
44
  - !ruby/object:Gem::Version
@@ -55,6 +46,7 @@ dependencies:
55
46
  - !ruby/object:Gem::Dependency
56
47
  name: minitest
57
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
58
50
  requirements:
59
51
  - - '='
60
52
  - !ruby/object:Gem::Version
@@ -62,6 +54,7 @@ dependencies:
62
54
  type: :runtime
63
55
  prerelease: false
64
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
65
58
  requirements:
66
59
  - - '='
67
60
  - !ruby/object:Gem::Version
@@ -74,19 +67,19 @@ extensions: []
74
67
  extra_rdoc_files:
75
68
  - README.rdoc
76
69
  files:
70
+ - lib/xml/smart_qname.rb
77
71
  - lib/xml/smart_domnamespaceset.rb
78
- - lib/xml/smart_domattribute.rb
72
+ - lib/xml/smart_dom.rb
79
73
  - lib/xml/smart_domnamespace.rb
80
- - lib/xml/smart_domnodeset.rb
74
+ - lib/xml/smart_processinginstruction.rb
81
75
  - lib/xml/smart_domtext.rb
82
- - lib/xml/smart_dom.rb
83
- - lib/xml/smart_domelement.rb
84
76
  - lib/xml/smart_domother.rb
85
- - lib/xml/smart_processinginstruction.rb
86
- - lib/xml/smart_qname.rb
87
77
  - lib/xml/XSDtoRNG.xsl
88
- - lib/xml/smart_domattributeset.rb
89
78
  - lib/xml/smart.rb
79
+ - lib/xml/smart_domelement.rb
80
+ - lib/xml/smart_domnodeset.rb
81
+ - lib/xml/smart_domattributeset.rb
82
+ - lib/xml/smart_domattribute.rb
90
83
  - example/EXAMPLE.xml
91
84
  - example/xpath_visual.rb
92
85
  - COPYING
@@ -94,122 +87,123 @@ files:
94
87
  - xml-smart.gemspec
95
88
  - README.rdoc
96
89
  - AUTHORS
97
- - test/tc_delete.rb
98
- - test/tc_xpath_attrs.rb
99
- - test/tc_xpath_functions.rb
100
- - test/tc_sort.rb
101
- - test/tc_xmlschema.rb
102
- - test/tc_move_elements.rb
103
- - test/tc_add.rb
90
+ - test/tc_nested.rb
104
91
  - test/tc_namespace_detailed.rb
92
+ - test/tc_xpath.rb
93
+ - test/tc_basic.rb
94
+ - test/tc_xinclude.rb
95
+ - test/tc_sort.rb
105
96
  - test/tc_copy.rb
106
- - test/tc_namespace_default.rb
107
- - test/tc_string.rb
108
- - test/tc_set_or_replace.rb
109
- - test/tc_write.rb
110
97
  - test/tc_xsl.rb
111
- - test/tc_create.rb
112
- - test/tc_nested.rb
113
98
  - test/tc_root.rb
114
- - test/tc_xpath_root.rb
115
- - test/tc_qname.rb
116
- - test/tc_todoc.rb
117
- - test/tc_concurrent.rb
99
+ - test/tc_xpath_attrs.rb
100
+ - test/tc_xmlschema.rb
118
101
  - test/tc_pi.rb
119
- - test/tc_basic.rb
120
102
  - test/tc_namespace_find.rb
103
+ - test/tc_add.rb
104
+ - test/tc_delete.rb
105
+ - test/tc_string.rb
106
+ - test/tc_qname.rb
107
+ - test/tc_namespace_default.rb
108
+ - test/tc_set_or_replace.rb
109
+ - test/tc_xpath_functions.rb
110
+ - test/tc_move_elements.rb
121
111
  - test/tc_relaxng.rb
122
- - test/tc_xinclude.rb
123
- - test/tc_xpath.rb
124
112
  - test/tc_version.rb
125
- - test/HELLO.xml
126
- - test/EXAMPLE.tmp.xml
113
+ - test/tc_concurrent.rb
114
+ - test/tc_xpath_root.rb
115
+ - test/tc_todoc.rb
116
+ - test/tc_write.rb
117
+ - test/tc_create.rb
118
+ - test/3.xml
127
119
  - test/2.xml
128
- - test/HELLO-MORE.xml
129
- - test/EXAMPLE-NSE.xml
130
120
  - test/EXAMPLE.xml
121
+ - test/EXAMPLE-NSE.xml
122
+ - test/EXAMPLE.tmp.xml
123
+ - test/XSL_DOCUMENT.xml
131
124
  - test/EXAMPLE.str.xml
132
125
  - test/concurrent.xml
133
- - test/EXAMPLE-NS.xml
134
- - test/XSL_DOCUMENT.xml
135
126
  - test/1.xml
127
+ - test/HELLO-MORE.xml
136
128
  - test/XSL_BASE.xml
137
- - test/3.xml
129
+ - test/EXAMPLE-NS.xml
130
+ - test/HELLO.xml
138
131
  - test/HELLO.rng
139
132
  - test/HELLO.xsd
140
- - test/XSL_BASE.xml.test
141
133
  - test/EXAMPLE.str.xml.test
134
+ - test/XSL_BASE.xml.test
142
135
  - test/EXAMPLE.tmp.xml.test
143
136
  - test/smartrunner.rb
144
137
  homepage: http://www.wst.univie.ac.at/~mangler/xml-smart/
145
138
  licenses:
146
139
  - LGPL-3
147
- metadata: {}
148
140
  post_install_message:
149
141
  rdoc_options: []
150
142
  require_paths:
151
143
  - lib
152
144
  required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
153
146
  requirements:
154
147
  - - ! '>='
155
148
  - !ruby/object:Gem::Version
156
149
  version: 1.9.3
157
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
158
152
  requirements:
159
153
  - - ! '>='
160
154
  - !ruby/object:Gem::Version
161
155
  version: '0'
162
156
  requirements: []
163
157
  rubyforge_project:
164
- rubygems_version: 2.0.3
158
+ rubygems_version: 1.8.23
165
159
  signing_key:
166
- specification_version: 4
160
+ specification_version: 3
167
161
  summary: An xml library that doesn't suck - since 2004.
168
162
  test_files:
169
- - test/tc_delete.rb
170
- - test/tc_xpath_attrs.rb
171
- - test/tc_xpath_functions.rb
172
- - test/tc_sort.rb
173
- - test/tc_xmlschema.rb
174
- - test/tc_move_elements.rb
175
- - test/tc_add.rb
163
+ - test/tc_nested.rb
176
164
  - test/tc_namespace_detailed.rb
165
+ - test/tc_xpath.rb
166
+ - test/tc_basic.rb
167
+ - test/tc_xinclude.rb
168
+ - test/tc_sort.rb
177
169
  - test/tc_copy.rb
178
- - test/tc_namespace_default.rb
179
- - test/tc_string.rb
180
- - test/tc_set_or_replace.rb
181
- - test/tc_write.rb
182
170
  - test/tc_xsl.rb
183
- - test/tc_create.rb
184
- - test/tc_nested.rb
185
171
  - test/tc_root.rb
186
- - test/tc_xpath_root.rb
187
- - test/tc_qname.rb
188
- - test/tc_todoc.rb
189
- - test/tc_concurrent.rb
172
+ - test/tc_xpath_attrs.rb
173
+ - test/tc_xmlschema.rb
190
174
  - test/tc_pi.rb
191
- - test/tc_basic.rb
192
175
  - test/tc_namespace_find.rb
176
+ - test/tc_add.rb
177
+ - test/tc_delete.rb
178
+ - test/tc_string.rb
179
+ - test/tc_qname.rb
180
+ - test/tc_namespace_default.rb
181
+ - test/tc_set_or_replace.rb
182
+ - test/tc_xpath_functions.rb
183
+ - test/tc_move_elements.rb
193
184
  - test/tc_relaxng.rb
194
- - test/tc_xinclude.rb
195
- - test/tc_xpath.rb
196
185
  - test/tc_version.rb
197
- - test/HELLO.xml
198
- - test/EXAMPLE.tmp.xml
186
+ - test/tc_concurrent.rb
187
+ - test/tc_xpath_root.rb
188
+ - test/tc_todoc.rb
189
+ - test/tc_write.rb
190
+ - test/tc_create.rb
191
+ - test/3.xml
199
192
  - test/2.xml
200
- - test/HELLO-MORE.xml
201
- - test/EXAMPLE-NSE.xml
202
193
  - test/EXAMPLE.xml
194
+ - test/EXAMPLE-NSE.xml
195
+ - test/EXAMPLE.tmp.xml
196
+ - test/XSL_DOCUMENT.xml
203
197
  - test/EXAMPLE.str.xml
204
198
  - test/concurrent.xml
205
- - test/EXAMPLE-NS.xml
206
- - test/XSL_DOCUMENT.xml
207
199
  - test/1.xml
200
+ - test/HELLO-MORE.xml
208
201
  - test/XSL_BASE.xml
209
- - test/3.xml
202
+ - test/EXAMPLE-NS.xml
203
+ - test/HELLO.xml
210
204
  - test/HELLO.rng
211
205
  - test/HELLO.xsd
212
- - test/XSL_BASE.xml.test
213
206
  - test/EXAMPLE.str.xml.test
207
+ - test/XSL_BASE.xml.test
214
208
  - test/EXAMPLE.tmp.xml.test
215
209
  - test/smartrunner.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: c6fe50c915c3a7d81224157afde21def4d21db00
4
- data.tar.gz: b1a6f82dc3175d7116a3ea227073bf6d34459015
5
- SHA512:
6
- metadata.gz: 5beb33b3d760bbc9ae90b49bf254846a6c4ae36f0d27113759a4ca6defc580c04a9d14d9368ec844d0004ea7ee427537b75d947259991d7a96917041f5d2ae06
7
- data.tar.gz: cedc50fdeea34258c2c0f4ebdae0ba2c79c2d0e82c4841a7b12a34e31f95583452145e22c184f37bb2f2bbec04f3866c652cb4d14a97bb9a83ea0611c118dd4d