Class: Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/roda/plugins/recheck_precompiled_assets.rb

Overview

Thread safe wrapper for the compiled asset metadata hash. Does not wrap all hash methods, only a few that are used.

Instance Method Summary collapse

Constructor Details

#initializeCompiledAssetsHash

Returns a new instance of CompiledAssetsHash.



21
22
23
24
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 21

def initialize
  @hash = {}
  @mutex = Mutex.new
end

Instance Method Details

#[](key) ⇒ Object



26
27
28
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 26

def [](key)
  @mutex.synchronize{@hash[key]}
end

#[]=(key, value) ⇒ Object



30
31
32
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 30

def []=(key, value)
  @mutex.synchronize{@hash[key] = value}
end

#each(&block) ⇒ Object



40
41
42
43
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 40

def each(&block)
  @mutex.synchronize{@hash.dup}.each(&block)
  self
end

#replace(hash) ⇒ Object



34
35
36
37
38
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 34

def replace(hash)
  hash = hash.instance_variable_get(:@hash) if (CompiledAssetsHash === hash)
  @mutex.synchronize{@hash.replace(hash)}
  self
end

#to_json(*args) ⇒ Object



45
46
47
# File 'lib/roda/plugins/recheck_precompiled_assets.rb', line 45

def to_json(*args)
  @mutex.synchronize{@hash.dup}.to_json(*args)
end