yamlrc 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-11-19
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday! Load and layers similarly named yaml configs from common locations.
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/yamlrc.rb
6
+ test/test_yamlrc.rb
data/README.txt ADDED
@@ -0,0 +1,80 @@
1
+ = yamlrc
2
+
3
+ == DESCRIPTION:
4
+
5
+ Simply loads a yaml file from
6
+ one of a number of directories
7
+ layering them on each other.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * loads yaml files.
12
+
13
+ == SYNOPSIS:
14
+
15
+ NOTE: top level yaml element should be a hash.
16
+
17
+ config = Yamlrc.load("myconfig.yaml")
18
+ checks /etc/myconfig.yaml
19
+ checks ~/myconfig.yaml
20
+ and returns its contents.
21
+
22
+ -- /etc/myconfig.yaml --
23
+ :default:
24
+ :user: reader
25
+ :pass: secret
26
+
27
+ -- ~/myconfig.yaml --
28
+ :default:
29
+ :host: otherhost
30
+ :user: ted
31
+ :pass: bettersecret
32
+ :dev:
33
+ :user: bill
34
+ :pass: changeme
35
+
36
+ -- whatever.rb --
37
+ require 'yamlrc'
38
+ require 'pp'
39
+ config = Yamlrc.load("myconfig.yaml")
40
+ pp config
41
+ => {:default=>{:host=>"otherhost", :user=>"ted", :pass=>"bettersecret"},
42
+ :dev=>{:user=>"bill", :pass=>"changeme"}}
43
+
44
+
45
+ == REQUIREMENTS:
46
+
47
+ * yaml
48
+
49
+ == INSTALL:
50
+
51
+ (if you haven't already)
52
+ > sudo gem install gem_cutter
53
+ > gem tumble
54
+
55
+ > sudo gem install yamlrc
56
+
57
+ == LICENSE:
58
+
59
+ (The MIT License)
60
+
61
+ Copyright (c) 2009 Andrew Nutter-Upham
62
+
63
+ Permission is hereby granted, free of charge, to any person obtaining
64
+ a copy of this software and associated documentation files (the
65
+ 'Software'), to deal in the Software without restriction, including
66
+ without limitation the rights to use, copy, modify, merge, publish,
67
+ distribute, sublicense, and/or sell copies of the Software, and to
68
+ permit persons to whom the Software is furnished to do so, subject to
69
+ the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be
72
+ included in all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
75
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
77
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
78
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
79
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
80
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'hoe'
4
+ require './lib/yamlrc.rb'
5
+
6
+ Hoe.spec 'yamlrc' do
7
+ developer "Andrew Nutter-Upham", "andynu+yamlrc@gmail.com"
8
+ end
9
+
10
+ # vim: ft=ruby:
data/lib/yamlrc.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'yaml'
2
+ class Yamlrc
3
+ VERSION = '1.0.0'
4
+ CONFIG_DIRECTORIES = [ "/etc", ENV['HOME'], File.dirname($0) ]
5
+ def self.load(config_name)
6
+ return {} if config_name.nil?
7
+ config = {}
8
+ CONFIG_DIRECTORIES.each do |dir|
9
+ file = File.join(dir,config_name)
10
+ if( File.exists?(file) )
11
+ config.merge! YAML.load_file(file)
12
+ end
13
+ end
14
+ return config
15
+ end
16
+ end
17
+
@@ -0,0 +1,13 @@
1
+ require "test/unit"
2
+ require "yamlrc"
3
+
4
+ class Yamlrc
5
+ CONFIG_DIRECTORIES = [File.dirname(__FILE__)]
6
+ end
7
+
8
+ class TestYamlrc < Test::Unit::TestCase
9
+ def test_currentdir
10
+ assert_equal({}, Yamlrc.load(nil))
11
+ assert_equal({:category => {:a => 1, :b => 2, :c => 3}}, Yamlrc.load("test_config.yaml"))
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yamlrc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Nutter-Upham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-19 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: |-
26
+ Simply loads a yaml file from
27
+ one of a number of directories
28
+ layering them on each other.
29
+ email:
30
+ - andynu+yamlrc@gmail.com
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ files:
40
+ - History.txt
41
+ - Manifest.txt
42
+ - README.txt
43
+ - Rakefile
44
+ - lib/yamlrc.rb
45
+ - test/test_yamlrc.rb
46
+ has_rdoc: true
47
+ homepage:
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --main
53
+ - README.txt
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: yamlrc
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Simply loads a yaml file from one of a number of directories layering them on each other.
75
+ test_files:
76
+ - test/test_yamlrc.rb