yahoo_quote 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -32,7 +32,7 @@ puts quote.field_mappings.keys
32
32
 
33
33
  ## Configuration
34
34
 
35
- Use /tmp to keep a simple cache:
35
+ Specify a directory to keep a simple file-based cache:
36
36
 
37
37
  ```ruby
38
38
  YahooQuote::Configuration.cache_dir = "/tmp"
@@ -2,12 +2,12 @@ module YahooQuote
2
2
  class Configuration
3
3
 
4
4
  def self.cache_dir=(path)
5
- if !path
6
- @@cache_dir = path
5
+ if !path || path.to_s.empty?
6
+ @@cache_dir = nil
7
7
  else
8
- dir = path.to_s
9
- Dir.mkdir(dir) unless dir.empty? || File.directory?(dir)
10
- @@cache_dir = dir
8
+ path = Pathname.new(path) if path.is_a? String
9
+ path.mkdir unless path.directory?
10
+ @@cache_dir = path
11
11
  end
12
12
  end
13
13
 
@@ -1,3 +1,3 @@
1
1
  module YahooQuote
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/yahoo_quote.rb CHANGED
@@ -46,8 +46,10 @@ module YahooQuote
46
46
  end
47
47
 
48
48
  def clear_cache
49
- Dir.glob(File.join(YahooQuote::Configuration.cache_dir, '*.csv')).each {|f|
50
- File.unlink f }
49
+ if cache_response?
50
+ Pathname.glob(YahooQuote::Configuration.cache_dir.join('*.csv')).each {|f|
51
+ f.unlink}
52
+ end
51
53
  end
52
54
 
53
55
  def quote_url
@@ -1,5 +1,6 @@
1
1
  require 'yahoo_quote'
2
2
  require 'minitest/autorun'
3
+ require 'pathname'
3
4
  require 'fakeweb'
4
5
 
5
6
  # TODO test 2 things: make intermediate dirs for cache and permissions
@@ -10,7 +11,13 @@ class TestYahooQuote < MiniTest::Unit::TestCase
10
11
  FakeWeb.allow_net_connect = false
11
12
  FakeWeb.register_uri(:get, @url_regexp, :response => File.read("test/fakeweb/aapl_good.csv"))
12
13
 
13
- @cache_dir = File.join('test', 'cache')
14
+ @cache_dir = Pathname.new('test/cache')
15
+ end
16
+
17
+ def remove_dir(dir_path)
18
+ return unless dir_path.exist?
19
+ dir_path.each_child {|p| p.unlink}
20
+ dir_path.unlink
14
21
  end
15
22
 
16
23
  def test_empty_arguments
@@ -66,14 +73,39 @@ class TestYahooQuote < MiniTest::Unit::TestCase
66
73
  assert !cached_quote.cache_response?
67
74
  end
68
75
 
76
+ def test_create_cache_dir
77
+ remove_dir @cache_dir
78
+ assert !@cache_dir.exist?
79
+ YahooQuote::Configuration.cache_dir = @cache_dir
80
+ assert @cache_dir.exist?
81
+ YahooQuote::Configuration.cache_dir = nil
82
+ end
83
+
84
+ def test_clear_cache_when_no_cache
85
+ quote = YahooQuote::Quote.new('AAPL', ['Name'])
86
+ quote.clear_cache
87
+ end
88
+
89
+ def test_clear_cache_when_empty_string
90
+ YahooQuote::Configuration.cache_dir = ''
91
+ quote = YahooQuote::Quote.new('AAPL', ['Name'])
92
+ quote.clear_cache
93
+ end
94
+
69
95
  def test_clear_cache
70
96
  YahooQuote::Configuration.cache_dir = @cache_dir
71
97
  quote = YahooQuote::Quote.new('AAPL', ['Name'])
72
98
  assert Dir.glob(File.join(@cache_dir, '*.csv')).size > 0, 'No files stored in cache'
73
99
  quote.clear_cache
74
100
  assert_equal 0, Dir.glob(File.join(@cache_dir, '*.csv')).size
75
- # We don't want to cache responses for other tests
76
101
  YahooQuote::Configuration.cache_dir = nil
77
- assert !quote.cache_response?
102
+ end
103
+
104
+ def test_save_cache_dir_as_pathname
105
+ dir_string = @cache_dir.to_s
106
+ assert dir_string.is_a?(String)
107
+ YahooQuote::Configuration.cache_dir = dir_string
108
+ assert YahooQuote::Configuration.cache_dir.is_a?(Pathname)
109
+ YahooQuote::Configuration.cache_dir = nil
78
110
  end
79
111
  end
data/yahoo_quote.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{Easy interaction with Yahoo Finance API}
13
13
 
14
14
  s.add_development_dependency "fakeweb"
15
+ s.add_development_dependency "ruby-debug19"
15
16
 
16
17
  s.rubyforge_project = "yahoo_quote"
17
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo_quote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-21 00:00:00.000000000Z
12
+ date: 2012-02-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fakeweb
16
- requirement: &2153217660 !ruby/object:Gem::Requirement
16
+ requirement: &2157617700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,18 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153217660
24
+ version_requirements: *2157617700
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby-debug19
27
+ requirement: &2157617280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2157617280
25
36
  description: Easy interaction with Yahoo Finance API
26
37
  email:
27
38
  - bcarreno@yahoo.com