using_yaml 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +40 -1
- data/VERSION +1 -1
- data/lib/using_yaml/open_hash.rb +35 -22
- data/lib/using_yaml/patches/array.rb +5 -0
- data/lib/using_yaml/patches/hash.rb +1 -1
- data/lib/using_yaml.rb +1 -0
- data/spec/using_yaml/using_yaml_spec.rb +9 -2
- data/using_yaml.gemspec +2 -1
- metadata +2 -1
data/README.rdoc
CHANGED
@@ -41,7 +41,46 @@ From Gemcutter:
|
|
41
41
|
|
42
42
|
== Pathname
|
43
43
|
|
44
|
-
|
44
|
+
By default, UsingYAML will look for .yml files in your home directory. There are several ways to configure this:
|
45
|
+
|
46
|
+
=== With strings:
|
47
|
+
|
48
|
+
class ExampleUsage
|
49
|
+
include UsingYAML
|
50
|
+
|
51
|
+
using_yaml :example, :path => '/your/path/here'
|
52
|
+
end
|
53
|
+
|
54
|
+
=== Using a Proc:
|
55
|
+
|
56
|
+
class ExampleUsage
|
57
|
+
include UsingYAML
|
58
|
+
|
59
|
+
using_yaml :example, :path => lambda { |c| c.pathname }
|
60
|
+
attr_accessor :pathname
|
61
|
+
end
|
62
|
+
|
63
|
+
example = ExampleUsage.new
|
64
|
+
example.pathname = '/your/path/here'
|
65
|
+
|
66
|
+
=== Overriding using_yaml_path:
|
67
|
+
|
68
|
+
class ExampleUsage
|
69
|
+
include UsingYAML
|
70
|
+
|
71
|
+
using_yaml :example
|
72
|
+
|
73
|
+
def using_yaml_path
|
74
|
+
'/your/code/here'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
== Error messages
|
80
|
+
|
81
|
+
By default, UsingYAML will return nil for missing files. It will also complain on STDERR. If you want to disable the complaint:
|
82
|
+
|
83
|
+
UsingYAML.squelch!
|
45
84
|
|
46
85
|
== Note on Patches/Pull Requests
|
47
86
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/lib/using_yaml/open_hash.rb
CHANGED
@@ -1,31 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
hash
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
module OpenHash
|
2
|
+
class << self
|
3
|
+
def from_hash(hash, pathname = nil)
|
4
|
+
Module.new do
|
5
|
+
hash.each_pair do |key, value|
|
6
|
+
define_method(key) do
|
7
|
+
value.respond_to?(:to_ohash) ? value.to_ohash : value
|
8
|
+
end
|
9
|
+
|
10
|
+
define_method("#{key}=") do |value|
|
11
|
+
case value
|
12
|
+
when Hash
|
13
|
+
send(:[]=, key, value.to_ohash)
|
14
|
+
else
|
15
|
+
send(:[]=, key, value)
|
16
|
+
end
|
17
|
+
end
|
12
18
|
end
|
13
|
-
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
if pathname
|
21
|
+
define_method(:save) do
|
22
|
+
File.open(pathname, 'w') do |f|
|
23
|
+
f.puts self.to_yaml
|
24
|
+
end
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
def from_array(array, pathname = nil)
|
31
|
+
Module.new do
|
32
|
+
array.each do |e|
|
33
|
+
e.to_ohash(e)
|
34
|
+
end
|
35
|
+
|
36
|
+
if pathname
|
37
|
+
define_method(:save) do
|
38
|
+
File.open(pathname, 'w') do |f|
|
39
|
+
f.puts self.to_yaml
|
40
|
+
end
|
41
|
+
end
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
data/lib/using_yaml.rb
CHANGED
@@ -10,7 +10,14 @@ describe 'UsingYAML#core' do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return valid settings files" do
|
13
|
-
YAML.stubs(:load_file).with(anything).returns({})
|
14
|
-
@person.children.should == {}
|
13
|
+
YAML.stubs(:load_file).with(anything).returns({ 'foo' => 'bar' })
|
14
|
+
@person.children.should == { 'foo' => 'bar' }
|
15
|
+
@person.children.foo.should == 'bar'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should work with arrays" do
|
19
|
+
YAML.stubs(:load_file).with(anything).returns([ { 'foo' => 'bar' } ])
|
20
|
+
@person.children.class.name.should == 'Array'
|
21
|
+
@person.children.first.should == { 'foo' => 'bar' }
|
15
22
|
end
|
16
23
|
end
|
data/using_yaml.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{using_yaml}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marc Bowes"]
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"lib/using_yaml.rb",
|
27
27
|
"lib/using_yaml/open_hash.rb",
|
28
|
+
"lib/using_yaml/patches/array.rb",
|
28
29
|
"lib/using_yaml/patches/hash.rb",
|
29
30
|
"spec/spec_helper.rb",
|
30
31
|
"spec/using_yaml/path_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: using_yaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Bowes
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- VERSION
|
41
41
|
- lib/using_yaml.rb
|
42
42
|
- lib/using_yaml/open_hash.rb
|
43
|
+
- lib/using_yaml/patches/array.rb
|
43
44
|
- lib/using_yaml/patches/hash.rb
|
44
45
|
- spec/spec_helper.rb
|
45
46
|
- spec/using_yaml/path_spec.rb
|