Class: Butler::Plugin::ConfigProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/butler/plugin/configproxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, base = "") ⇒ ConfigProxy

Returns a new instance of ConfigProxy.



16
17
18
19
20
# File 'lib/butler/plugin/configproxy.rb', line 16

def initialize(config, base="")
	@config = config
	@base   = base
	@mutex  = Mutex.new
end

Instance Method Details

#[](key, *args) ⇒ Object

access a config key, hands off to Configuration#[] and prepends Plugin#base to the key



37
38
39
# File 'lib/butler/plugin/configproxy.rb', line 37

def [](key, *args)
	@config[(key.empty? ? @base : "#{@base}/#{key}"), *args]
end

#[]=(key, value) ⇒ Object

assign a config key, hands off to Configuration#[]= and prepends Plugin#base to the key



31
32
33
# File 'lib/butler/plugin/configproxy.rb', line 31

def []=(key, value)
	@config[key.empty? ? @base : "#{@base}/#{key}"] = value
end

#delete(key) ⇒ Object

delete a config key, hands off to Configuration#delete and prepends Plugin#base to the key



50
51
52
# File 'lib/butler/plugin/configproxy.rb', line 50

def delete(key)
	@config.delete(key.empty? ? @base : "#{@base}/#{key}")
end

#exist?(key) ⇒ Boolean Also known as: has_key?

test existence of a key, hands off to Configuration#exist? and prepends Plugin#base to the key

Returns:

  • (Boolean)


43
44
45
# File 'lib/butler/plugin/configproxy.rb', line 43

def exist?(key)
	@config.exist?(key.empty? ? @base : "#{@base}/#{key}")
end

#synchronizeObject

Synchronize access to this piece of config



23
24
25
26
27
# File 'lib/butler/plugin/configproxy.rb', line 23

def synchronize
	@mutex.synchronize {
		yield self
	}
end