R
Roberto Cm
I'm wondering how to extend the config-yaml parser at
http://www.mjijackson.com/2010/02/flexible-ruby-config-objects so I can
write to the file through the variable.
right now it works like this:
yaml_data = "
---
database: mydb
auth:
user: myuser
pass: mypass
"
require 'yaml'
config = Config.new(YAML.load(yaml_data))
config.auth.user # "myuser"
and I want to add some magic so I can do this instead:
config = Config.new(yaml_filename_variable)
config.a = "test"
p config.a
=> "test"
config.write()
config = nil
config = Config.new(yaml_filename_variable)
p config-a
=> "test"
to load the file on new(), I changed the class like this:
require 'yaml'
class ConfigYaml
def initialize(file)
if file.nil?? then
yaml_conf = YAML.load_file(file)
end
@data = case yaml_conf.nil?
when true then YAML.load_file(file)
else {}
end
update!(data)
end
private
...
http://www.mjijackson.com/2010/02/flexible-ruby-config-objects so I can
write to the file through the variable.
right now it works like this:
yaml_data = "
---
database: mydb
auth:
user: myuser
pass: mypass
"
require 'yaml'
config = Config.new(YAML.load(yaml_data))
config.auth.user # "myuser"
and I want to add some magic so I can do this instead:
config = Config.new(yaml_filename_variable)
config.a = "test"
p config.a
=> "test"
config.write()
config = nil
config = Config.new(yaml_filename_variable)
p config-a
=> "test"
to load the file on new(), I changed the class like this:
require 'yaml'
class ConfigYaml
def initialize(file)
if file.nil?? then
yaml_conf = YAML.load_file(file)
end
@data = case yaml_conf.nil?
when true then YAML.load_file(file)
else {}
end
update!(data)
end
private
...