using_yaml 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/lib/using_yaml.rb CHANGED
@@ -5,10 +5,6 @@ require 'using_yaml/patches/hash'
5
5
 
6
6
  module UsingYAML
7
7
  class << self
8
- def cache
9
- @@cache ||= {}
10
- end
11
-
12
8
  def path(klass)
13
9
  return @@path[klass] if defined?(@@path)
14
10
  end
@@ -47,22 +43,23 @@ module UsingYAML
47
43
  else
48
44
  filename = key
49
45
  options = value
50
- using_yaml_file(filename, options)
46
+ using_yaml_file(filename)
51
47
  end
52
48
  end
53
49
  end
54
50
  end
55
51
  end
56
52
 
57
- def using_yaml_file(filename, options = {})
53
+ def using_yaml_file(filename)
58
54
  define_method(filename) do
59
55
  pathname = using_yaml_path.join("#{filename}.yml").expand_path
60
- data = UsingYAML.cache[pathname]
56
+ cache = (@using_yaml_cache ||= {})
57
+ data = @using_yaml_cache[pathname]
61
58
  return data if data
62
59
 
63
60
  begin
64
61
  data = YAML.load_file(pathname).to_ohash(pathname)
65
- UsingYAML.cache[pathname] = data
62
+ @using_yaml_cache[pathname] = data
66
63
  rescue Exception => e
67
64
  $stderr.puts "(UsingYAML) Could not load #{filename}: #{e.message}" unless UsingYAML.squelched?
68
65
  nil
@@ -72,6 +69,8 @@ module UsingYAML
72
69
  end
73
70
 
74
71
  module InstanceMethods
72
+ attr_accessor :using_yaml_cache
73
+
75
74
  def using_yaml_path
76
75
  path = UsingYAML.path(self.class.name)
77
76
  path = path.call(self) if path.is_a? Proc
data/spec/spec_helper.rb CHANGED
@@ -13,3 +13,14 @@ class Person
13
13
  include UsingYAML
14
14
  using_yaml :children
15
15
  end
16
+
17
+ def reset_person!
18
+ Person.class_eval do
19
+ include UsingYAML
20
+ using_yaml :children
21
+ end
22
+
23
+ UsingYAML.path = ['Person', nil]
24
+ @person.using_yaml_path = nil
25
+ @person.using_yaml_cache = nil
26
+ end
@@ -1,15 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- def reset_person!
4
- Person.class_eval do
5
- include UsingYAML
6
- using_yaml :children
7
- end
8
-
9
- UsingYAML.path = ['Person', nil]
10
- @person.using_yaml_path = nil
11
- end
12
-
13
3
  describe "UsingYAML#paths" do
14
4
  before(:each) do
15
5
  @person = Person.new
data/using_yaml.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{using_yaml}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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"]
12
- s.date = %q{2010-02-13}
12
+ s.date = %q{2010-02-15}
13
13
  s.description = %q{"Load, save and use YAML files as if they were objects"}
14
14
  s.email = %q{marcbowes@gmail.com}
15
15
  s.extra_rdoc_files = [
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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Bowes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-13 00:00:00 +02:00
12
+ date: 2010-02-15 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency