Bluebie, Jenna wrote:

And on that note, I think I'll go checkout the latest shoes and see if I can implement this right now myself.

Here's the configurator we use at work:

require 'yaml'
require 'pathname'

class AppConfig
  def self.app_name=(app_name)
    @@app_name = app_name
  end

  def self. filename
    Pathname.new("~/.#{@@app_name}").expand_path
  end

  private

    def self.method_missing(name)
      # @config ||= YAML.load(ERB.new(IO.read(filename)).result)
                # no forgit de erb, mon!
      @config ||= YAML.load(IO.read(filename))
      return @config[name.to_s]
    end
end

require 'test/unit'
require 'rubygems'
require 'assert2'  #  sudo gem install assert2 now!

class AppConfigTest < Test::Unit::TestCase

  def setup
    AppConfig.app_name = 'test'
    sample = { 'window' => { 'x' => 42, 'y' => 43 }, 'volume' => 65 }
    File.open(AppConfig.filename, 'w'){|f| f.write(sample.to_yaml) }
  end

  def test_volume
    assert{ AppConfig.volume == 65 }
  end

  def test_window
    assert{ AppConfig.window['x'] == 42 }
    assert{ AppConfig.window['y'] == 43 }
  end

end


Reply via email to