Skip to content

Instantly share code, notes, and snippets.

@kostia
Created February 23, 2012 14:56
Show Gist options
  • Save kostia/1893175 to your computer and use it in GitHub Desktop.
Save kostia/1893175 to your computer and use it in GitHub Desktop.
Plugin for HashWithStructAccess for loading YAML from string and from files

HashWithStructAccessYamlLoader

# In you Gemfile
gem("hash_with_struct_access_yaml_loader", :git => "git://gist.github.com/1893175.git")

# In your code
HashWithStructAccess.load_yaml_file("load_me.yml")
Gem::Specification.new do |s|
s.name = "hash_with_struct_access_yaml_loader"
s.version = "0.0.1"
s.platform = Gem::Platform::RUBY
s.require_path = "."
s.files = %w(hash_with_struct_access_yaml_loader.rb)
s.add_dependency("hash_with_struct_access", "0.0.2")
end
require "yaml"
require "hash_with_struct_access"
class HashWithStructAccessYamlLoader
module Plugin
def load_yaml(string)
new(YAML.load(string))
end
def load_yaml_file(path)
load_yaml(File.read(path))
end
end
HashWithStructAccess.extend(HashWithStructAccessYamlLoader::Plugin)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment