yami 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/LICENSE +20 -0
- data/README.md +33 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/deps.rip +1 -0
- data/lib/yami.rb +40 -0
- data/test/helper.rb +3 -0
- data/test/yami_test.rb +28 -0
- metadata +65 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Doug Tangren
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Yami
|
2
|
+
|
3
|
+
Key-Value configuration from a yaml store
|
4
|
+
|
5
|
+
# Install
|
6
|
+
|
7
|
+
### [Gemcutter](http://gemcutter.org/)
|
8
|
+
|
9
|
+
> sudo gem install yami
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
|
13
|
+
require 'yami'
|
14
|
+
|
15
|
+
# set path to persistent yaml store
|
16
|
+
Yami.file = File.join(
|
17
|
+
File.dirname(__FILE__), *%w(path to config.yaml)
|
18
|
+
)
|
19
|
+
|
20
|
+
# read
|
21
|
+
Yami[:option] #=> value
|
22
|
+
|
23
|
+
# read with default
|
24
|
+
Yami[:flavor, "banana"]
|
25
|
+
|
26
|
+
# write
|
27
|
+
Yami[:shuttle] = {
|
28
|
+
:speed => :fast
|
29
|
+
}
|
30
|
+
|
31
|
+
# fin.
|
32
|
+
|
33
|
+
2009 doug tangren (softprops)
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "yami"
|
5
|
+
gemspec.summary = "Yaml persisted config"
|
6
|
+
gemspec.description = "Yaml persisted config"
|
7
|
+
gemspec.email = "d.tangren@gmail.com"
|
8
|
+
gemspec.homepage = "http://github.com/softprops/yami"
|
9
|
+
gemspec.authors = ["softprops"]
|
10
|
+
end
|
11
|
+
Jeweler::GemcutterTasks.new
|
12
|
+
rescue LoadError
|
13
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
14
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/deps.rip
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
git://github.com/defunkt/fakefs.git
|
data/lib/yami.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Yami
|
4
|
+
extend self
|
5
|
+
attr_accessor :file
|
6
|
+
|
7
|
+
def [](k, default = nil)
|
8
|
+
ensure_read
|
9
|
+
@config[k] || default
|
10
|
+
end
|
11
|
+
|
12
|
+
def []=(k,v)
|
13
|
+
ensure_read
|
14
|
+
@config[k] = v
|
15
|
+
write
|
16
|
+
end
|
17
|
+
|
18
|
+
def reload!
|
19
|
+
read
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def ensure_read
|
25
|
+
raise(
|
26
|
+
RuntimeError.new(
|
27
|
+
"No file defined. Assign one with Config.file='./foo.yaml'"
|
28
|
+
)
|
29
|
+
) unless @file
|
30
|
+
read unless @config
|
31
|
+
end
|
32
|
+
|
33
|
+
def read
|
34
|
+
File.open(@file) { |f| @config = YAML::load(f) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def write
|
38
|
+
File.open(@file, 'w+') { |f| YAML::dump(@config, f) }
|
39
|
+
end
|
40
|
+
end
|
data/test/helper.rb
ADDED
data/test/yami_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w(helper))
|
2
|
+
|
3
|
+
class YamiTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
FakeFS.activate!
|
7
|
+
path = File.join(
|
8
|
+
File.dirname(__FILE__), 'test.yaml'
|
9
|
+
)
|
10
|
+
File.open(path, "w") { |f| YAML::dump({},f) }
|
11
|
+
Yami.file = path
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
FakeFS::FileSystem.clear
|
16
|
+
FakeFS.deactivate!
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_read_and_write_value
|
20
|
+
Yami[:foo] = "bar"
|
21
|
+
assert_equal "bar", Yami[:foo]
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_read_value_with_default
|
25
|
+
assert_equal 10, Yami[:zoo, 10]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yami
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- softprops
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-15 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Yaml persisted config
|
17
|
+
email: d.tangren@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- LICENSE
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- deps.rip
|
32
|
+
- lib/yami.rb
|
33
|
+
- test/helper.rb
|
34
|
+
- test/yami_test.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/softprops/yami
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --charset=UTF-8
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.5
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Yaml persisted config
|
63
|
+
test_files:
|
64
|
+
- test/helper.rb
|
65
|
+
- test/yami_test.rb
|