Using Yaml
This Gem allows you to easily associate YAML files with classes
Installation
From Gemcutter:
sudo gem install using_yaml
Usage
require 'rubygems'
require 'using_yaml'
class ExampleUsage
include UsingYAML
using_yaml :some, :settings
end
example = ExampleUsage.new
# Load "OpenHash" from pathname.join('some.yml')
example.some #=> { "key" => "value" }
# Behaves like a normal hash
example.some['key'] #=> "value"
# AND like an object
example.some.key #=> "value"
# Setter methods work too
example.some.key = "another value"
# Saves to original location
example.save #=> writes
# .. and the same for settings
example.settings #=> "{ ... }"
Pathname
By default, UsingYAML will look for .yml files in your home directory. There are several ways to configure this:
With strings:
class ExampleUsage
include UsingYAML
using_yaml :example, :path => '/your/path/here'
end
Using a Proc:
class ExampleUsage
include UsingYAML
using_yaml :example, :path => lambda { |c| c.pathname }
attr_accessor :pathname
end
example = ExampleUsage.new
example.pathname = '/your/path/here'
Overriding using_yaml_path:
class ExampleUsage
include UsingYAML
using_yaml :example
def using_yaml_path
'/your/code/here'
end
end
Error messages
By default, UsingYAML will return nil for missing files. It will also complain on STDERR. If you want to disable the complaint:
UsingYAML.squelch!
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010 Marc Bowes. See LICENSE for details.