Class: Lafcadio::LafcadioConfig

Inherits:
Hash
  • Object
show all
Defined in:
lib/lafcadio/util.rb

Overview

LafcadioConfig is a Hash that takes its data from the config file. You’ll have to set the location of that file before using it: Use LafcadioConfig.set_filename.

LafcadioConfig expects its data to be colon-delimited, one key-value pair to a line. For example:

dbuser:user
dbpassword:password
dbname:lafcadio_test
dbhost:localhost
dbtype:Mysql ("Mysql" is the default; select "Pg" for Postgres)

Constant Summary collapse

@@value_hash =
{}
@@instances =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLafcadioConfig

Returns a new instance of LafcadioConfig.



47
48
49
# File 'lib/lafcadio/util.rb', line 47

def initialize
	@@value_hash.each { |key, value| self[key] = value }
end

Class Method Details

.[]=(k, v) ⇒ Object



21
22
23
24
# File 'lib/lafcadio/util.rb', line 21

def self.[]=( k, v )
	@@value_hash[k] = v
	@@instances.each do |instance| instance[k] = v; end
end

.newObject



26
27
28
29
30
# File 'lib/lafcadio/util.rb', line 26

def self.new
	inst = super
	@@instances << inst
	inst
end

.set_filename(filename) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/lafcadio/util.rb', line 32

def self.set_filename(filename)
	@@value_hash = {}
	if filename
		File.new( filename ).each_line { |line|
			line.chomp =~ /^(.*?):(.*)$/
			self[$1] = $2
		}
	end
end

.set_values(value_hash) ⇒ Object



42
43
44
45
# File 'lib/lafcadio/util.rb', line 42

def self.set_values( value_hash )
	@@value_hash = ( value_hash.nil? ? {} : value_hash )
	ObjectStore.db_type = @@value_hash['dbtype'] if @@value_hash['dbtype']
end