using_yaml 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/using_yaml.rb +8 -2
- data/spec/using_yaml/path_spec.rb +15 -5
- data/using_yaml.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/using_yaml.rb
CHANGED
@@ -32,6 +32,8 @@ module UsingYAML
|
|
32
32
|
|
33
33
|
module ClassMethods
|
34
34
|
def using_yaml(*args)
|
35
|
+
include InstanceMethods
|
36
|
+
|
35
37
|
args.each do |arg|
|
36
38
|
case arg
|
37
39
|
when Symbol, String
|
@@ -54,7 +56,7 @@ module UsingYAML
|
|
54
56
|
|
55
57
|
def using_yaml_file(filename, options = {})
|
56
58
|
define_method(filename) do
|
57
|
-
pathname =
|
59
|
+
pathname = using_yaml_path.join("#{filename}.yml").expand_path
|
58
60
|
data = UsingYAML.cache[pathname]
|
59
61
|
return data if data
|
60
62
|
|
@@ -67,9 +69,13 @@ module UsingYAML
|
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
72
|
+
end
|
70
73
|
|
74
|
+
module InstanceMethods
|
71
75
|
def using_yaml_path
|
72
|
-
|
76
|
+
path = UsingYAML.path(self.class.name)
|
77
|
+
path = path.call(self) if path.is_a? Proc
|
78
|
+
@using_yaml_path ||= Pathname.new(path || ENV['HOME'])
|
73
79
|
end
|
74
80
|
|
75
81
|
def using_yaml_path=(path)
|
@@ -7,7 +7,7 @@ def reset_person!
|
|
7
7
|
end
|
8
8
|
|
9
9
|
UsingYAML.path = ['Person', nil]
|
10
|
-
|
10
|
+
@person.using_yaml_path = nil
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "UsingYAML#paths" do
|
@@ -16,12 +16,12 @@ describe "UsingYAML#paths" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should return $HOME for non-existant pathnames" do
|
19
|
-
|
19
|
+
@person.using_yaml_path.expand_path.to_s.should == ENV['HOME']
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should return path/to/defined for globally set pathnames" do
|
23
|
-
|
24
|
-
|
23
|
+
@person.using_yaml_path = "global"
|
24
|
+
@person.using_yaml_path.expand_path.to_s.should =~ /global/
|
25
25
|
reset_person!
|
26
26
|
end
|
27
27
|
|
@@ -29,7 +29,17 @@ describe "UsingYAML#paths" do
|
|
29
29
|
Person.class_eval do
|
30
30
|
using_yaml :children, :path => "local"
|
31
31
|
end
|
32
|
-
|
32
|
+
@person.using_yaml_path.expand_path.to_s.should =~ /local/
|
33
|
+
reset_person!
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return path/to/lambda for lambda paths" do
|
37
|
+
Person.class_eval do
|
38
|
+
using_yaml :children, :path => lambda { |s| s.pathname }
|
39
|
+
attr_accessor :pathname
|
40
|
+
end
|
41
|
+
@person.pathname = 'lambda'
|
42
|
+
@person.using_yaml_path.expand_path.to_s.should =~ /lambda/
|
33
43
|
reset_person!
|
34
44
|
end
|
35
45
|
end
|
data/using_yaml.gemspec
CHANGED