Class: Nanoc3::Extra::Validators::Links::ThreadsafeHashEnumerator
- Inherits:
-
Object
- Object
- Nanoc3::Extra::Validators::Links::ThreadsafeHashEnumerator
- Defined in:
- lib/nanoc3/extra/validators/links.rb
Overview
Enumerates all key-value pairs of a given hash in a thread-safe way.
This class is a helper class, which means that it is not used directly by nanoc. Future versions of nanoc may no longer contain this class. Do not depend on this class to be available.
Instance Method Summary (collapse)
-
- (ThreadsafeHashEnumerator) initialize(hash)
constructor
Creates a new enumerator for the given hash.
-
- (Array) next_pair
Returns the next key-value pair in the hash.
Constructor Details
- (ThreadsafeHashEnumerator) initialize(hash)
Creates a new enumerator for the given hash.
62 63 64 65 66 |
# File 'lib/nanoc3/extra/validators/links.rb', line 62 def initialize(hash) @hash = hash @unprocessed_keys = @hash.keys.dup @mutex = Mutex.new end |
Instance Method Details
- (Array) next_pair
Returns the next key-value pair in the hash.
72 73 74 75 76 77 |
# File 'lib/nanoc3/extra/validators/links.rb', line 72 def next_pair @mutex.synchronize do key = @unprocessed_keys.shift return (key ? [ key, @hash[key] ] : nil) end end |