Class: Saxon::ItemType::LazyReadOnlyHash

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/saxon/item_type.rb

Overview

lazy-loading Hash so we can avoid eager-loading saxon Jars, which prevents using external Saxon Jars unless the user is more careful than they should have to be.

Instance Method Summary collapse

Constructor Details

#initialize(&init_block) ⇒ LazyReadOnlyHash

Returns a new instance of LazyReadOnlyHash.



18
19
20
21
22
# File 'lib/saxon/item_type.rb', line 18

def initialize(&init_block)
  @init_block = init_block
  @load_mutex = Mutex.new
  @loaded_hash = nil
end

Instance Method Details

#[](key) ⇒ Object



24
25
26
27
# File 'lib/saxon/item_type.rb', line 24

def [](key)
  ensure_loaded!
  loaded_hash[key]
end

#each(&block) ⇒ Object



34
35
36
37
# File 'lib/saxon/item_type.rb', line 34

def each(&block)
  ensure_loaded!
  loaded_hash.each(&block)
end

#fetch(*args, &block) ⇒ Object



29
30
31
32
# File 'lib/saxon/item_type.rb', line 29

def fetch(*args, &block)
  ensure_loaded!
  loaded_hash.fetch(*args, &block)
end