atk_toolbox 0.0.44 → 0.0.45
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/atk/download.rb +2 -4
- data/lib/atk/extra_file_utils.rb +36 -11
- data/lib/atk_toolbox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99c34226e0e1d77b1616de7e5e16cce6a8496eb47fda2020fa76ee2597c62498
|
4
|
+
data.tar.gz: b0725578fae82ad3df7139e6a7fc546a664ab423aff7ec561d34e4dcb0628c04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b2096e55bdc352c77064a619ea7ae813bda4d2afd49b022e32c2ebe1cfdcc71e6695ba28504f9f7b7517798f27401b050c2580a6fc8e44c82504cae79d4cb15
|
7
|
+
data.tar.gz: bf3a9017e56c9ff1b06698c2254162666a9b12533834e37fce980797eabb63b5906dcbbd7f06e87c076cccfbc01b8a49b2d24b8930370a0498db363ffff2da04
|
data/lib/atk/download.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'fileutils'
|
3
|
+
require_relative './extra_file_utils'
|
3
4
|
|
4
5
|
def download(input_1=nil, from:nil, url:nil, as:nil)
|
5
6
|
# argument checking
|
@@ -33,8 +34,5 @@ def download(input_1=nil, from:nil, url:nil, as:nil)
|
|
33
34
|
raise message_
|
34
35
|
end#if
|
35
36
|
#end argument checking
|
36
|
-
|
37
|
-
FileUtils.makedirs(File.dirname(file_name))
|
38
|
-
# actually download the file
|
39
|
-
IO.write(file_name, open(the_url).read)
|
37
|
+
FileSys.write(open(URI.encode(the_url)).read, to: file_name)
|
40
38
|
end
|
data/lib/atk/extra_file_utils.rb
CHANGED
@@ -19,15 +19,40 @@ class String
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
def in_dir(path_to_somewhere)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
class FileSys
|
23
|
+
def self.in_dir(path_to_somewhere)
|
24
|
+
# save the current working dir
|
25
|
+
current_dir = Dir.pwd
|
26
|
+
# switch dirs
|
27
|
+
Dir.chdir(path_to_somewhere)
|
28
|
+
# do the thing
|
29
|
+
output = yield
|
30
|
+
# switch back
|
31
|
+
Dir.chdir(current_dir)
|
32
|
+
return output
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.write(data, to:nil)
|
36
|
+
# make sure the containing folder exists
|
37
|
+
FileUtils.makedirs(File.dirname(to))
|
38
|
+
# actually download the file
|
39
|
+
IO.write(to, data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.read(filepath)
|
43
|
+
begin
|
44
|
+
return IO.read(filepath)
|
45
|
+
rescue => exception
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.delete(filepath)
|
51
|
+
begin
|
52
|
+
return File.delete(filepath)
|
53
|
+
# if file doesnt exist, thats fine
|
54
|
+
rescue Errno::ENOENT => exception
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
end
|
33
58
|
end
|
data/lib/atk_toolbox/version.rb
CHANGED