Class: Nanoc3::Extra::Validators::Links::ThreadsafeHashEnumerator

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(hash) ⇒ ThreadsafeHashEnumerator

Creates a new enumerator for the given hash.

Parameters:

  • hash (Hash)

    The hash for which the enumerator should return key-value pairs



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

#next_pairArray

Returns the next key-value pair in the hash.

Returns:

  • (Array)

    An array containing the key and the corresponding value of teh next key-value pair



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