summaryrefslogtreecommitdiff
path: root/lib/custodian/settings.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-23 14:35:45 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-23 14:35:45 +0000
commit2141f8fe4f5823a3d14a4320527ab20e93529a99 (patch)
treec6a6d01c8f87e62c8bb02512bffdc8abce40ce97 /lib/custodian/settings.rb
parent3f0cb049f297a631593b43b5ac37183c3f95824c (diff)
Added this file to the project - not-yet used.
Diffstat (limited to 'lib/custodian/settings.rb')
-rw-r--r--lib/custodian/settings.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/lib/custodian/settings.rb b/lib/custodian/settings.rb
new file mode 100644
index 0000000..2708570
--- /dev/null
+++ b/lib/custodian/settings.rb
@@ -0,0 +1,98 @@
+
+require 'singleton'
+
+
+#
+# A class which encapsulates some global-settings from the custodian configuration file.
+#
+# The configuration file is optional, and we have defaults for every value.
+#
+# This class is a singleton to avoid having to re-parse the configuration file more than
+# once per program-launch.
+#
+module Custodian
+
+ class Settings
+
+ include Singleton
+
+
+ #
+ # The parsed key=values store
+ #
+ attr_reader :settings
+
+
+ #
+ # Holder to mark whether we've loaded our file.
+ #
+ attr_reader :parsed
+
+
+
+
+ #
+ # Load the configuration file; called only once.
+ #
+ def _load
+ @parsed = true
+ @settings = Hash.new()
+
+ #
+ # The global configuration file.
+ #
+ file = "/etc/custodian/custodian.cfg"
+ return unless( File.exists?( file ) )
+
+ #
+ # Load and "parse" the key=value content.
+ #
+ File.open( file, "r").each_line do |line|
+ next if ( line.nil? || line =~ /^#/ )
+ if ( line =~ /^(.*)=(.*)$/ )
+ key = $1.dup
+ val = $2.dup
+ key.strip!
+ val.strip!
+ @settings[key] = val
+ end
+ end
+ end
+
+
+
+
+ #
+ # Have we loaded our data?
+ #
+ def _loaded?
+ @parsed
+ end
+
+
+
+
+ #
+ # The timeout period for all tests
+ #
+ def timeout
+ _load() unless( _loaded? )
+
+ @settings['timeout'] || 30
+ end
+
+
+
+
+ #
+ # The beanstalkd server address
+ #
+ def queue_server
+ _load() unless( _loaded? )
+
+ @settings['queue'] || "127.0.0.1:13300"
+ end
+
+
+ end
+end