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
21
# File 'lib/butler/plugin/configproxy.rb', line 16

def initialize(config, base="")
	@config = config
	@base   = base
	@mutex  = Mutex.new
	FileUtils.mkdir_p("#{config.base}/#{File.dirname(base)}")
end

Instance Method Details

#[](key, *args) ⇒ Object

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



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

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



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

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



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

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)


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

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

#synchronizeObject

Synchronize access to this piece of config



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

def synchronize
	@mutex.synchronize {
		yield self
	}
end