activestorage-sftp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c1cad83fd43e3324294dd2c0081f8b61a76c003
4
- data.tar.gz: 99d47be472b87031a8d506d0630b35e45b5d1061
3
+ metadata.gz: 53fb9c020a024d48787fccfbdd311b88f1eef5b6
4
+ data.tar.gz: 396a0b2ffc2cde6bb0f88bf169cdbf2932110855
5
5
  SHA512:
6
- metadata.gz: 4e73d5a932d849c9a901a4065950ec1600fe1a2cb1446bd80f6f99239a3c59f4c53e81054eeb57f86f43e1f81897e60830d8cccd74abfa14380eaaa7b31781f8
7
- data.tar.gz: 20732912bfbf3332da9a2264d9bd7179cc94dee9533be29f3c71402bc82afa4f25b69d67c948f34bb33cd1cc070f31653eac80ecb5026827375eb1c6b86a85a6
6
+ metadata.gz: 930f62d8856cfda94bfa90285ab6c59fc5d3d4ccdd14ce851a2dece838e5f78114438c87195d2c467738aa01031be7eea591e1f7244f40222507aaa52f30ffbe
7
+ data.tar.gz: 5a7f980c04c712750beec2f4a328bc676d0be570cc9c52854c46c2e053d0f99fe69f6a47b955fb3157eb554d5efff98579d9bf0b1cb14099ce8718d2b57689b1
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/activestorage-sftp.svg)](https://badge.fury.io/rb/activestorage-sftp)
2
+
1
3
  Remote DiskService through SFTP, for ActiveStorage.
2
4
 
3
5
  ## Installation
@@ -9,13 +9,14 @@ module ActiveStorage
9
9
 
10
10
  MAX_CHUNK_SIZE = 64.kilobytes.freeze
11
11
 
12
- attr_reader :host, :user, :root, :public_host
12
+ attr_reader :host, :user, :root, :public_host, :public_root
13
13
 
14
- def initialize(host:, user:, public_host: nil, root: './')
14
+ def initialize(host:, user:, public_host: nil, root: './', public_root: nil)
15
15
  @host = host
16
16
  @user = user
17
17
  @root = root
18
18
  @public_host = public_host
19
+ @public_root = public_root
19
20
  end
20
21
 
21
22
  def upload(key, io, checksum: nil, **)
@@ -30,8 +31,7 @@ module ActiveStorage
30
31
 
31
32
  def download(key, chunk_size: MAX_CHUNK_SIZE, &block)
32
33
  if chunk_size > MAX_CHUNK_SIZE
33
- # TODO Error
34
- raise "Maximum chunk size: #{MAX_CHUNK_SIZE}"
34
+ raise ChunkSizeError, "Maximum chunk size: #{MAX_CHUNK_SIZE}"
35
35
  end
36
36
  if block_given?
37
37
  instrument :streaming_download, key: key do
@@ -45,8 +45,7 @@ module ActiveStorage
45
45
  if response.eof?
46
46
  eof = true
47
47
  elsif !response.ok?
48
- # TODO Error
49
- raise "SFTP Response Error"
48
+ raise SFTPResponseError, response.code
50
49
  else
51
50
  chunk = response[:data]
52
51
  block.call(chunk)
@@ -76,8 +75,7 @@ module ActiveStorage
76
75
  def download_chunk(key, range)
77
76
  instrument :download_chunk, key: key, range: range do
78
77
  if range.size > MAX_CHUNK_SIZE
79
- # TODO Error
80
- raise "Maximun chunk size: #{MAX_CHUNK_SIZE}"
78
+ raise ChunkSizeError, "Maximum chunk size: #{MAX_CHUNK_SIZE}"
81
79
  end
82
80
  chunk = StringIo.new
83
81
  through_sftp do |sftp|
@@ -179,6 +177,10 @@ module ActiveStorage
179
177
  { "Content-Type" => content_type }
180
178
  end
181
179
 
180
+ def path_for(key)
181
+ File.join folder_for(key), key
182
+ end
183
+
182
184
  protected
183
185
  def through_sftp(&block)
184
186
  Net::SFTP.start(@host, @user) do |sftp|
@@ -186,10 +188,6 @@ module ActiveStorage
186
188
  end
187
189
  end
188
190
 
189
- def path_for(key)
190
- File.join folder_for(key), key
191
- end
192
-
193
191
  def folder_for(key)
194
192
  File.join root, relative_folder_for(key)
195
193
  end
@@ -4,6 +4,7 @@ require "active_storage/service/sftp_service"
4
4
  module ActiveStorage
5
5
  module SFTP
6
6
  class Error < StandardError; end
7
- # Your code goes here...
7
+ class ChunkSizeError < Error; end
8
+ class SFTPResponseError < Error; end
8
9
  end
9
10
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveStorage
2
2
  module SFTP
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage-sftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - treenewbee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2019-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails