Class: Fairy::Conf

Inherits:
Object
  • Object
show all
Defined in:
lib/fairy/share/conf.rb

Overview

}

Direct Known Subclasses

DefaultConf

Defined Under Namespace

Classes: DefaultConf

Constant Summary collapse

PROPS =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(super_conf = nil, opts = {}) ⇒ Conf

Returns a new instance of Conf.



26
27
28
29
# File 'lib/fairy/share/conf.rb', line 26

def initialize(super_conf = nil, opts = {})
  @super_conf = super_conf
  @values = opts
end

Class Method Details

.configure_common_confObject



387
388
389
390
391
392
393
394
395
# File 'lib/fairy/share/conf.rb', line 387

def Conf.configure_common_conf
  Thread.abort_on_exception = CONF.DEBUG_THREAD_ABORT_ON_EXCEPTION

  TCPSocket.do_not_reverse_lookup = CONF.SOCK_DO_NOT_REVERSE_LOOKUP

  if CONF.USE_RESOLV_REPLACE
    require "resolv-replace"
  end
end

.def_prop(prop, reader = nil, setter = nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/fairy/share/conf.rb', line 32

def def_prop(prop, reader = nil, setter = nil)
	PROPS.push prop
	reader = "def #{prop}; value(:#{prop}); end" unless reader
	setter = "def #{prop}=(value); @values[:#{prop}] = value; end" unless setter
	module_eval reader
	module_eval setter
#	DefaultConf.module_eval reader
end

.def_prop_relative_path(prop, path, base_prop = :HOME) ⇒ Object Also known as: def_rpath



41
42
43
44
# File 'lib/fairy/share/conf.rb', line 41

def def_prop_relative_path(prop, path, base_prop = :HOME)
	def_prop(prop, 
		 "def #{prop}; value(:#{prop}) || self.#{base_prop}+'/'+'#{path}'; end")
end

Instance Method Details

#base_conf=(conf) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/fairy/share/conf.rb', line 59

def base_conf=(conf)
  if @super_conf
	@super_conf.base_conf = conf
  else
	@super_conf = conf
  end
end

#HOMEObject



78
79
80
# File 'lib/fairy/share/conf.rb', line 78

def HOME
  File.expand_path(value(:HOME))
end

#propsObject



55
56
57
# File 'lib/fairy/share/conf.rb', line 55

def props
  PROPS
end

#set_values(hash) ⇒ Object



67
68
69
70
71
# File 'lib/fairy/share/conf.rb', line 67

def set_values(hash)
  for key, value in hash
	@values[key] = value
  end
end

#value(prop) ⇒ Object



48
49
50
51
52
53
# File 'lib/fairy/share/conf.rb', line 48

def value(prop)
  if (v = @values[prop]).nil?
	@super_conf && v = @super_conf.value(prop)
  end
  v
end