using_yaml 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,31 +18,8 @@ rescue LoadError
18
18
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
19
  end
20
20
 
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
26
- end
27
-
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
- task :test => :check_dependencies
42
-
43
- task :default => :test
44
-
45
21
  require 'rake/rdoctask'
22
+
46
23
  Rake::RDocTask.new do |rdoc|
47
24
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
25
 
@@ -51,3 +28,13 @@ Rake::RDocTask.new do |rdoc|
51
28
  rdoc.rdoc_files.include('README*')
52
29
  rdoc.rdoc_files.include('lib/**/*.rb')
53
30
  end
31
+
32
+ require 'spec/rake/spectask'
33
+
34
+ desc "Run specs"
35
+ Spec::Rake::SpecTask.new do |t|
36
+ t.spec_files = Rake::FileList["spec/**/*_spec.rb"]
37
+ t.spec_opts = ["-c"]
38
+ end
39
+
40
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/using_yaml.rb CHANGED
@@ -9,14 +9,20 @@ module UsingYAML
9
9
  @@cache ||= {}
10
10
  end
11
11
 
12
- def config(klass, key, value = nil)
13
- @@config ||= {}
14
- case value
15
- when nil
16
- (@@config[klass] ||= {})[key] = value
17
- else
18
- @@config[klass]
19
- end
12
+ def path(klass)
13
+ return @@path[klass] if defined?(@@path)
14
+ end
15
+
16
+ def path=(args)
17
+ (@@path ||= {})[args.first] = args.last
18
+ end
19
+
20
+ def squelch!
21
+ @@squelched = true
22
+ end
23
+
24
+ def squelched?
25
+ defined?(@@squelched) && @@squelched
20
26
  end
21
27
  end
22
28
 
@@ -33,10 +39,10 @@ module UsingYAML
33
39
  using_yaml_file(filename)
34
40
  when Hash
35
41
  arg.each do |key, value|
36
- case value
37
- when Symbol
38
- UsingYAML.config(self.class, key, value)
39
- when Hash
42
+ case key
43
+ when :path
44
+ UsingYAML.path = [self.inspect, value]
45
+ else
40
46
  filename = key
41
47
  options = value
42
48
  using_yaml_file(filename, options)
@@ -52,13 +58,22 @@ module UsingYAML
52
58
  data = UsingYAML.cache[pathname]
53
59
  return data if data
54
60
 
55
- data = YAML.load_file(pathname).to_ohash(pathname) rescue nil
56
- UsingYAML.cache[pathname] = data
61
+ begin
62
+ data = YAML.load_file(pathname).to_ohash(pathname)
63
+ UsingYAML.cache[pathname] = data
64
+ rescue Exception => e
65
+ $stderr.puts "(UsingYAML) Could not load #{filename}: #{e.message}" unless UsingYAML.squelched?
66
+ nil
67
+ end
57
68
  end
58
69
  end
59
70
 
60
71
  def using_yaml_path
61
- @using_yaml_path ||= Pathname.new(UsingYAML.config(self.class, :pathname) || File.dirname(__FILE__))
72
+ @using_yaml_path ||= Pathname.new(UsingYAML.path(self.inspect) || ENV['HOME'])
73
+ end
74
+
75
+ def using_yaml_path=(path)
76
+ @using_yaml_path = path && Pathname.new(path)
62
77
  end
63
78
  end
64
79
  end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'mocha'
4
+ require File.dirname(__FILE__) + '/../lib/using_yaml.rb'
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.mock_with :mocha
8
+ end
9
+
10
+ UsingYAML.squelch!
11
+
12
+ class Person
13
+ include UsingYAML
14
+ using_yaml :children
15
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
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
+ describe "UsingYAML#paths" do
14
+ before(:each) do
15
+ @person = Person.new
16
+ end
17
+
18
+ it "should return $HOME for non-existant pathnames" do
19
+ Person.using_yaml_path.expand_path.to_s.should == ENV['HOME']
20
+ end
21
+
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/
25
+ reset_person!
26
+ end
27
+
28
+ it "should return path/to/defined for locally set pathnames" do
29
+ Person.class_eval do
30
+ using_yaml :children, :path => "local"
31
+ end
32
+ Person.using_yaml_path.expand_path.to_s.should =~ /local/
33
+ reset_person!
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe 'UsingYAML#core' do
4
+ before(:each) do
5
+ @person = Person.new
6
+ end
7
+
8
+ it "should return nil for invalid settings files" do
9
+ @person.children.should be_nil
10
+ end
11
+
12
+ it "should return valid settings files" do
13
+ YAML.stubs(:load_file).with(anything).returns({})
14
+ @person.children.should == {}
15
+ end
16
+ end
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.1.1"
8
+ s.version = "0.2.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"]
12
- s.date = %q{2010-02-12}
12
+ s.date = %q{2010-02-13}
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 = [
@@ -26,8 +26,9 @@ Gem::Specification.new do |s|
26
26
  "lib/using_yaml.rb",
27
27
  "lib/using_yaml/open_hash.rb",
28
28
  "lib/using_yaml/patches/hash.rb",
29
- "test/helper.rb",
30
- "test/test_using_yaml.rb",
29
+ "spec/spec_helper.rb",
30
+ "spec/using_yaml/path_spec.rb",
31
+ "spec/using_yaml/using_yaml_spec.rb",
31
32
  "using_yaml.gemspec"
32
33
  ]
33
34
  s.homepage = %q{http://github.com/marcbowes/UsingYAML}
@@ -36,8 +37,9 @@ Gem::Specification.new do |s|
36
37
  s.rubygems_version = %q{1.3.5}
37
38
  s.summary = %q{"Load, save and use YAML files"}
38
39
  s.test_files = [
39
- "test/test_using_yaml.rb",
40
- "test/helper.rb"
40
+ "spec/using_yaml/path_spec.rb",
41
+ "spec/using_yaml/using_yaml_spec.rb",
42
+ "spec/spec_helper.rb"
41
43
  ]
42
44
 
43
45
  if s.respond_to? :specification_version then
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.1.1
4
+ version: 0.2.0
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-12 00:00:00 +02:00
12
+ date: 2010-02-13 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,8 +41,9 @@ files:
41
41
  - lib/using_yaml.rb
42
42
  - lib/using_yaml/open_hash.rb
43
43
  - lib/using_yaml/patches/hash.rb
44
- - test/helper.rb
45
- - test/test_using_yaml.rb
44
+ - spec/spec_helper.rb
45
+ - spec/using_yaml/path_spec.rb
46
+ - spec/using_yaml/using_yaml_spec.rb
46
47
  - using_yaml.gemspec
47
48
  has_rdoc: true
48
49
  homepage: http://github.com/marcbowes/UsingYAML
@@ -73,5 +74,6 @@ signing_key:
73
74
  specification_version: 3
74
75
  summary: "\"Load, save and use YAML files\""
75
76
  test_files:
76
- - test/test_using_yaml.rb
77
- - test/helper.rb
77
+ - spec/using_yaml/path_spec.rb
78
+ - spec/using_yaml/using_yaml_spec.rb
79
+ - spec/spec_helper.rb
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'using_yaml'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestUsingYAML < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end