file_loader 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9382fbacb05be26be6f65d6fb26354e77955a687
4
- data.tar.gz: da0602da95eb580284f8ae6a2bd20d33adcddcc9
3
+ metadata.gz: c2dba6a88d0bc2a635b05de63555bc3adcc243d5
4
+ data.tar.gz: 73a03edea7501fac6e51631781a2e702610fc4fd
5
5
  SHA512:
6
- metadata.gz: 65a51540e5457f9230edb63055e0128d1242572c6d90e923a4dc9f3b5ab80583191166e9461999161b21e91cdbb49beb93cb17b56462d3fa0be1ef75e3d3d00c
7
- data.tar.gz: 45bfbaa1796384b268a9a98a27e8fa92664549505e9a38bfcd91fa0d95aeecb509d25e2070b343653ef9b763c3dec7b998d9fa0d20ef01ce3c3329ea4540e0af
6
+ metadata.gz: fd26b2eb440143655f54ebb1b8ac30a6c7a8c4bd6a71292095c5edff2b741dfab12830a20f99175859766b4a5e96749e1eaa122e8c389943bdb4396da3ba728c
7
+ data.tar.gz: 94f0d5faa5a468ab7e1ef49ab68d352ceda17796c4259e4c0b5f7a128ac1749b41b0fa50a9a0342a44f744774b826df121b22cd9fc2e83ec6a5b8bbb1bbbea0c
data/lib/file_loader.rb CHANGED
@@ -38,6 +38,25 @@ module FileLoader
38
38
  res
39
39
  end
40
40
 
41
+ def exists?(url, opts = {})
42
+ purl = parse_url(url)
43
+ case purl[:protocol]
44
+ when 'http', 'https', 'ftp'
45
+ cmd = "curl -I \"#{url}\""
46
+ when 'scp'
47
+ cmd = "ssh -oBatchMode=yes -oStrictHostKeyChecking=no "
48
+ cmd += build_url(user: purl[:user] || opts[:user], password: purl[:password] || opts[:password], host: purl[:host])
49
+ cmd += ' "test -f '
50
+ cmd += purl[:path]
51
+ cmd += '"'
52
+ when nil
53
+ cmd = 'test -f ' + purl[:path]
54
+ else
55
+ return false
56
+ end
57
+ system(cmd + ' 2>/dev/null 1>/dev/null')
58
+ end
59
+
41
60
  def download(src, dst, opts = {})
42
61
  pdst = parse_url(dst = dst.shellescape)
43
62
  raise "Unsupported dst protocol #{pdst[:protocol]}" if pdst[:protocol]
@@ -90,7 +109,7 @@ module FileLoader
90
109
  cmd += '" && scp -r -oBatchMode=yes -oStrictHostKeyChecking=no '
91
110
  cmd += "-l #{opts[:speed_limit]} " if opts[:speed_limit]
92
111
  cmd += "#{src} \""
93
- cmd += build_url(user: pdst[:user] || opts[:user], password: pdst[:password], host: pdst[:host], path: pdst[:path])
112
+ cmd += build_url(user: pdst[:user] || opts[:user], password: pdst[:password] || opts[:password], host: pdst[:host], path: pdst[:path])
94
113
  cmd += '"'
95
114
  end
96
115
  when nil
@@ -1,3 +1,3 @@
1
1
  module FileLoader
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_loader
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
  - novikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-16 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 2.2.2
76
+ rubygems_version: 2.4.3
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: File loader