oga 1.3.0 → 1.3.1

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: 8c2fbbee6b62ef30eefb291f25d092cf5241b7d7
4
- data.tar.gz: 035e4c3f0dc6c22ea74cb35e027a7610334ed362
3
+ metadata.gz: 0230f47af567902efa1575a8447774e4a35fb50c
4
+ data.tar.gz: 5cae5f489883d8c8e9f76309e8c1e9d9e8e7c9cc
5
5
  SHA512:
6
- metadata.gz: 603ecb90ae452afc024dc64da6bd6afcfc6c4d0f1ed29151a6584460b54b0e3d84e12e2a7612d129ccdf897fd55b2d88aa5f056e14089f66c143a275b8cee985
7
- data.tar.gz: 05cc8ae719b4ec9c6ca1f725db14183893d438b0361ccf55b4afe61faba623eff8347bf95b7aa693ee21e70b2a8fe217aaa43f6659a397c22ac1d18fee825f51
6
+ metadata.gz: 092aca9cb1b728a572e397efde33e2a4a9897e11938aa34638bbcb0d361ebc7af9d85962920c898ecfe09b531d7a78667471a7f6aa7e776b4a650ddadbf72bf0
7
+ data.tar.gz: ba98f9c6d4b9bcbdc7356678b00543e31ecdb4fd0657c61efd998a015a9f7e3e9564d577f5950237ecd9a173121cc3349a310431cc126f34797659b03b73c535
data/README.md CHANGED
@@ -177,13 +177,17 @@ process and bundled inside the Gem itself.
177
177
 
178
178
  ## Thread Safety
179
179
 
180
- Documents parsed using Oga are thread-safe as long as they are not modified by
181
- multiple threads at the same time. Querying documents using XPath can be done by
182
- multiple threads just fine. Write operations, such as removing attributes, are
183
- _not_ thread-safe and should not be done by multiple threads at once.
180
+ Oga does not use a unsynchronized global mutable state. As a result of this you
181
+ can parse/create documents concurrently without any problems. Modifying
182
+ documents concurrently can lead to bugs as these operations are not
183
+ synchronized.
184
184
 
185
- It is advised that you do not share parsed documents between threads unless you
186
- _really_ have to.
185
+ Some querying operations will cache data in instance variables, without
186
+ synchronization. An example is `Oga::XML::Element#namespace` which will cache an
187
+ element's namespace after the first call.
188
+
189
+ In general it's recommended to _not_ use the same document in multiple threads
190
+ at the same time.
187
191
 
188
192
  ## Namespace Support
189
193
 
data/lib/oga.rb CHANGED
@@ -55,6 +55,7 @@ require 'oga/ruby/generator'
55
55
 
56
56
  require 'oga/xpath/lexer'
57
57
  require 'oga/xpath/parser'
58
+ require 'oga/xpath/context'
58
59
  require 'oga/xpath/compiler'
59
60
  require 'oga/xpath/conversion'
60
61
 
@@ -1,3 +1,3 @@
1
1
  module Oga
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end # Oga
@@ -12,6 +12,11 @@ module Oga
12
12
  # @return [Oga::LRU]
13
13
  CACHE = LRU.new
14
14
 
15
+ # Context for compiled Procs. As compiled Procs do not mutate the
16
+ # enclosing environment we can just re-use the same instance without
17
+ # synchronization.
18
+ CONTEXT = Context.new
19
+
15
20
  # Wildcard for node names/namespace prefixes.
16
21
  STAR = '*'
17
22
 
@@ -86,7 +91,7 @@ module Oga
86
91
  generator = Ruby::Generator.new
87
92
  source = generator.process(proc_ast)
88
93
 
89
- eval(source)
94
+ CONTEXT.evaluate(source)
90
95
  ensure
91
96
  reset
92
97
  end
@@ -0,0 +1,17 @@
1
+ module Oga
2
+ module XPath
3
+ # Class used as the context for compiled XPath Procs.
4
+ #
5
+ # The binding of this class is used for the binding of Procs compiled by
6
+ # {Compiler}. Not using a specific binding would result in the procs
7
+ # using the binding of {Compiler#compile}, which could lead to race
8
+ # conditions.
9
+ class Context
10
+ # @param [String] string
11
+ # @return [Proc]
12
+ def evaluate(string)
13
+ binding.eval(string)
14
+ end
15
+ end # Context
16
+ end # XPath
17
+ end # Oga
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oga
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yorick Peterse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-06 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -199,6 +199,7 @@ files:
199
199
  - lib/oga/xml/traversal.rb
200
200
  - lib/oga/xml/xml_declaration.rb
201
201
  - lib/oga/xpath/compiler.rb
202
+ - lib/oga/xpath/context.rb
202
203
  - lib/oga/xpath/conversion.rb
203
204
  - lib/oga/xpath/lexer.rb
204
205
  - lib/oga/xpath/parser.rb