using_yaml 0.2.0 → 0.3.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.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 = self.class.using_yaml_path.join("#{filename}.yml").expand_path
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
- @using_yaml_path ||= Pathname.new(UsingYAML.path(self.inspect) || ENV['HOME'])
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
- Person.using_yaml_path = nil
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
- Person.using_yaml_path.expand_path.to_s.should == ENV['HOME']
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
- Person.using_yaml_path = "global"
24
- Person.using_yaml_path.expand_path.to_s.should =~ /global/
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
- Person.using_yaml_path.expand_path.to_s.should =~ /local/
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{using_yaml}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
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"]
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Bowes