Class: Spacewalk::Config
- Inherits:
-
Object
- Object
- Spacewalk::Config
- Defined in:
- lib/spacewalk/config.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(path = "/etc/sysconfig/rhn/up2date") ⇒ Config
constructor
A new instance of Config.
- #method_missing(name) ⇒ Object
Constructor Details
#initialize(path = "/etc/sysconfig/rhn/up2date") ⇒ Config
Returns a new instance of Config.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/spacewalk/config.rb', line 3 def initialize path="/etc/sysconfig/rhn/up2date" @path = path @config = {} File.open path do |f| while l = f.gets # split <name>=<value>, drop everything else next unless l =~ /(\w+)=(.*)/ key = $1 val = $2 # fixme: handle array-type values @config[key.downcase] = val.empty? ? nil : val end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
22 23 24 |
# File 'lib/spacewalk/config.rb', line 22 def method_missing name @config[name.to_s.downcase] end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/spacewalk/config.rb', line 18 def [] key @config[key.downcase] end |