Class: Ccp::Data::KVS::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/ccp/data.rb

Instance Method Summary collapse

Constructor Details

#initialize(kvs) ⇒ Default

Returns a new instance of Default.



15
16
17
# File 'lib/ccp/data.rb', line 15

def initialize(kvs)
  @kvs = kvs
end

Instance Method Details

#[]=(key, val) ⇒ Object



19
20
21
22
# File 'lib/ccp/data.rb', line 19

def []=(key, val)
  return if @kvs.exist?(key)
  @kvs[key] = val
end

#regsiter_lazy(key, block) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
# File 'lib/ccp/data.rb', line 24

def regsiter_lazy(key, block)
  return if @kvs.exist?(key)
  raise ArgumentError, "Lazy default value needs block: #{key}" unless block
  @kvs[key] = LazyValue.new(block)
end