Class: RQ::ConfigFile
- Inherits:
-
Object
- Object
- RQ::ConfigFile
- Defined in:
- lib/rq-0.1.7/configfile.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{{{
LIBDIR + 'defaultconfig.txt'
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.any(basename, *dirnames) ⇒ Object
}}}.
- .gen_template(arg = nil) ⇒ Object
-
.load_default ⇒ Object
}}}.
-
.munge(buf) ⇒ Object
}}}.
Instance Method Summary collapse
-
#initialize(path) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
-
#to_hash ⇒ Object
}}}.
Constructor Details
#initialize(path) ⇒ ConfigFile
Returns a new instance of ConfigFile.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rq-0.1.7/configfile.rb', line 54 def initialize path #{{{ @path = nil yaml = nil if path.nil? or path and path =~ /^\s*default/io yaml = self.class.load_default @path = 'DEFAULT' else path yaml = YAML::load(self.class.munge(open(path).read)) @path = path end self.update yaml #}}} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
53 54 55 |
# File 'lib/rq-0.1.7/configfile.rb', line 53 def path @path end |
Class Method Details
.any(basename, *dirnames) ⇒ Object
}}}
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rq-0.1.7/configfile.rb', line 34 def any(basename, *dirnames) #{{{ config = nil dirnames.each do |dirname| path = File::join dirname, basename if test ?e, path config = self::new(path) break end end config || self::new('default') #}}} end |
.gen_template(arg = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rq-0.1.7/configfile.rb', line 14 def gen_template(arg = nil) #{{{ @data ||= IO::read(DEFAULT_CONFIG) case arg when IO arg.write @data when String open(arg, 'w'){|f| f.write @data} else STDOUT.write @data end self #}}} end |
.load_default ⇒ Object
}}}
28 29 30 31 32 33 |
# File 'lib/rq-0.1.7/configfile.rb', line 28 def load_default #{{{ @data ||= IO::read(DEFAULT_CONFIG) @default ||= YAML::load(munge(@data)) || {} #}}} end |
.munge(buf) ⇒ Object
}}}
47 48 49 50 51 |
# File 'lib/rq-0.1.7/configfile.rb', line 47 def munge buf #{{{ buf.gsub(%r/\t/o,' ') #}}} end |
Instance Method Details
#to_hash ⇒ Object
}}}
68 69 70 71 72 |
# File 'lib/rq-0.1.7/configfile.rb', line 68 def to_hash #{{{ {}.update self #}}} end |