ero_getter 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ero_getter"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["masarakki"]
@@ -14,7 +14,12 @@ class EroGetter
14
14
  klazz.new(url).run
15
15
  end
16
16
 
17
+
17
18
  class << self
19
+ def directory
20
+ File.join ENV['HOME'], 'ero_getter'
21
+ end
22
+
18
23
  def url_mapping
19
24
  @url_mapping ||= {}
20
25
  end
@@ -12,9 +12,11 @@ class EroGetter::Downloader
12
12
  end
13
13
 
14
14
  def mkdir(path)
15
- basedir = File.dirname(path)
16
- mkdir(basedir) unless File.exists?(basedir)
17
- Dir.mkdir(path)
15
+ unless File.exists?(path)
16
+ basedir = File.dirname(path)
17
+ mkdir(basedir) unless File.exists?(basedir)
18
+ Dir.mkdir(path)
19
+ end
18
20
  end
19
21
 
20
22
  def unzip(zip_data)
@@ -13,6 +13,14 @@ class EroGetter::Downloader::Base
13
13
  self.class.to_s.underscore
14
14
  end
15
15
 
16
+ def directory
17
+ unless @dir
18
+ @dir = File.join(EroGetter.directory, base_dir, sub_directory)
19
+ EroGetter::Downloader.mkdir(@dir)
20
+ end
21
+ @dir
22
+ end
23
+
16
24
  def http_client
17
25
  @http_client ||= HTTPClient.new
18
26
  end
@@ -58,9 +66,7 @@ class EroGetter::Downloader::Base
58
66
  def sub_directory(&block)
59
67
  define_method(:sub_directory) do
60
68
  unless instance_variable_defined?(:@sub_directory)
61
- dir = self.instance_eval(&block)
62
- EroGetter::Downloader.mkdir(dir)
63
- instance_variable_set(:@sub_directory, dir)
69
+ instance_variable_set(:@sub_directory, self.instance_eval(&block))
64
70
  end
65
71
  instance_variable_get(:@sub_directory)
66
72
  end
@@ -31,6 +31,7 @@ describe EroGetter::Downloader::Base do
31
31
  @dl = @klazz.new('http://example.net/10101010.html')
32
32
  @dl.stub(:open).and_return(File.open(sample_path('sample.html')))
33
33
  EroGetter::Downloader.stub(:mkdir).and_return(true)
34
+ EroGetter.stub('directory').and_return('/tmp')
34
35
  end
35
36
  its(:name) { should == 'NijiEro BBS' }
36
37
  its(:url_regex) { should == regex }
@@ -41,14 +42,8 @@ describe EroGetter::Downloader::Base do
41
42
  its(:url) { should == 'http://example.net/10101010.html' }
42
43
  its(:targets) { should == ['https://github.com/masarakki/ero_getter_server',
43
44
  'https://github.com/masarakki/ero_getter_chrome_extension'] }
44
- describe :sub_directory do
45
- its(:sub_directory) { should == 'ero_getter_server/ero_getter_chrome_extension' }
46
- it "mkdir only once" do
47
- EroGetter::Downloader.should_receive(:mkdir).with('ero_getter_server/ero_getter_chrome_extension').exactly(1)
48
- @dl.sub_directory
49
- @dl.sub_directory
50
- end
51
- end
45
+ its(:sub_directory) { should == 'ero_getter_server/ero_getter_chrome_extension' }
46
+ its(:directory) { should == '/tmp/test_class/ero_getter_server/ero_getter_chrome_extension' }
52
47
  end
53
48
  context :url_mismatch do
54
49
  it {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ero_getter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -180,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  segments:
182
182
  - 0
183
- hash: 1155287302627282076
183
+ hash: 4601793703788942628
184
184
  required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  none: false
186
186
  requirements: