remote_files 3.1.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/remote_files/abstract_store.rb +8 -0
- data/lib/remote_files/file.rb +9 -4
- data/lib/remote_files/file_store.rb +25 -3
- data/lib/remote_files/fog_store.rb +37 -6
- data/lib/remote_files/memory_store.rb +18 -1
- data/lib/remote_files/version.rb +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c031b3f95c929678e3ab56a3cc98c6aea47db1c294bfbd7b20a4390e90d06b6
|
4
|
+
data.tar.gz: c0665d4387cb9e15fca35e89387e6ac687b8b3c616d4d004892c6787596efe89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 646ff0467bf953702039d0240ca72fe56c0989d5639caa21778079ff4d5ae84014e85e9a191b48095b22dcafe70ba65819e52d771acb5da040fe418b6865b482
|
7
|
+
data.tar.gz: 45cdccb5afa27109216a3c4b56ba220de6410935dddcfde320b61a0642ffea945c3722f179c22b40fd8c8427098534fc93a06f7fc4042a8e2224fcf1d0707ad1
|
@@ -22,6 +22,14 @@ module RemoteFiles
|
|
22
22
|
raise "You need to implement #{self.class.name}:#directory_name"
|
23
23
|
end
|
24
24
|
|
25
|
+
def files(prefix = '')
|
26
|
+
raise "You need to implement #{self.class.name} #files"
|
27
|
+
end
|
28
|
+
|
29
|
+
def copy_to_store!(file, target_store)
|
30
|
+
raise "You need to implement #{self.class.name} #copy_to_store!"
|
31
|
+
end
|
32
|
+
|
25
33
|
def store!(file)
|
26
34
|
raise "You need to implement #{self.class.name}#store!"
|
27
35
|
end
|
data/lib/remote_files/file.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
module RemoteFiles
|
2
2
|
class File
|
3
|
-
attr_reader :content, :content_type, :identifier, :stored_in, :configuration
|
3
|
+
attr_reader :content, :content_type, :identifier, :stored_in, :configuration, :populate_stored_in, :last_update_ts
|
4
4
|
|
5
5
|
def initialize(identifier, options = {})
|
6
|
-
known_keys = [:identifier, :stored_in, :content_type, :configuration, :content]
|
6
|
+
known_keys = [:identifier, :stored_in, :content_type, :configuration, :content, :populate_stored_in, :last_update_ts]
|
7
7
|
known_keys.each do |key|
|
8
8
|
options[key] ||= options.delete(key.to_s)
|
9
9
|
end
|
10
10
|
|
11
11
|
@identifier = identifier
|
12
|
-
@stored_in = (options[:stored_in] || []).map(&:to_sym)
|
12
|
+
@stored_in = (options[:stored_in] || []).map(&:to_sym) # TODO: Refactor so that there are two classes: `File` and `FileCopy`
|
13
13
|
@content = options.delete(:content)
|
14
|
+
@last_update_ts = options[:last_update_ts] || Time.now
|
14
15
|
@content_type = options[:content_type]
|
15
16
|
@configuration = RemoteFiles::CONFIGURATIONS[(options[:configuration] || :default).to_sym]
|
16
17
|
@logger = options[:logger]
|
18
|
+
@populate_stored_in = options[:populate_stored_in]
|
17
19
|
@options = options
|
18
20
|
end
|
19
21
|
|
@@ -34,7 +36,8 @@ module RemoteFiles
|
|
34
36
|
:identifier => identifier,
|
35
37
|
:stored_in => stored_in,
|
36
38
|
:content_type => content_type,
|
37
|
-
:configuration => configuration.name
|
39
|
+
:configuration => configuration.name,
|
40
|
+
:populate_stored_in => populate_stored_in
|
38
41
|
)
|
39
42
|
end
|
40
43
|
|
@@ -79,6 +82,8 @@ module RemoteFiles
|
|
79
82
|
next unless file
|
80
83
|
@content = file.content
|
81
84
|
@content_type = file.content_type
|
85
|
+
# :populate_stored_in is a boolean
|
86
|
+
@stored_in = file.stored_in if @populate_stored_in
|
82
87
|
return true
|
83
88
|
rescue Error => e
|
84
89
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
# This is good for use in
|
4
|
+
# This is good for use in development
|
5
5
|
|
6
6
|
module RemoteFiles
|
7
7
|
class FileStore < AbstractStore
|
@@ -13,6 +13,21 @@ module RemoteFiles
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def files(prefix = '')
|
17
|
+
dir = directory + prefix
|
18
|
+
|
19
|
+
return [] unless dir.exist?
|
20
|
+
|
21
|
+
dir.children.reject do |child|
|
22
|
+
child.directory?
|
23
|
+
end.map do |child|
|
24
|
+
File.new(child.basename.to_s,
|
25
|
+
:stored_in => [self],
|
26
|
+
:last_update_ts => child.mtime
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
16
31
|
def store!(file)
|
17
32
|
file_name = directory + file.identifier
|
18
33
|
|
@@ -30,12 +45,19 @@ module RemoteFiles
|
|
30
45
|
end
|
31
46
|
end
|
32
47
|
|
48
|
+
def copy_to_store!(file, target_store)
|
49
|
+
FileUtils.cp(directory + file.identifier, target_store.directory + file.identifier)
|
50
|
+
end
|
51
|
+
|
33
52
|
def retrieve!(identifier)
|
34
|
-
|
53
|
+
path = directory + identifier
|
54
|
+
|
55
|
+
content = (path).read
|
35
56
|
|
36
57
|
RemoteFiles::File.new(identifier,
|
37
58
|
:content => content,
|
38
|
-
:stored_in => [self]
|
59
|
+
:stored_in => [self],
|
60
|
+
:last_update_ts => path.mtime
|
39
61
|
# what about content-type? maybe use the mime-types gem?
|
40
62
|
)
|
41
63
|
rescue Errno::ENOENT
|
@@ -7,6 +7,7 @@ module RemoteFiles
|
|
7
7
|
|
8
8
|
def store!(file)
|
9
9
|
success = directory.files.create(store_options(file))
|
10
|
+
# TODO: Probably get the last modified time
|
10
11
|
|
11
12
|
raise RemoteFiles::Error unless success
|
12
13
|
|
@@ -15,6 +16,10 @@ module RemoteFiles
|
|
15
16
|
raise RemoteFiles::Error, $!.message, $!.backtrace
|
16
17
|
end
|
17
18
|
|
19
|
+
def copy_to_store!(file, target_store)
|
20
|
+
target_store.connection.copy_object(directory_name, file.identifier, target_store.directory_name, file.identifier)
|
21
|
+
end
|
22
|
+
|
18
23
|
def retrieve!(identifier)
|
19
24
|
fog_file = directory.files.get(identifier)
|
20
25
|
|
@@ -23,7 +28,8 @@ module RemoteFiles
|
|
23
28
|
File.new(identifier,
|
24
29
|
:content => fog_file.body,
|
25
30
|
:content_type => fog_file.content_type,
|
26
|
-
:stored_in => [self]
|
31
|
+
:stored_in => [self],
|
32
|
+
:last_update_ts => fog_file.last_modified
|
27
33
|
)
|
28
34
|
rescue Fog::Errors::Error, Excon::Errors::Error
|
29
35
|
raise RemoteFiles::Error, $!.message, $!.backtrace
|
@@ -53,28 +59,53 @@ module RemoteFiles
|
|
53
59
|
raise RemoteFiles::Error, message
|
54
60
|
end
|
55
61
|
|
56
|
-
connection.delete_object(
|
62
|
+
connection.delete_object(directory_name, identifier)
|
57
63
|
rescue Fog::Errors::NotFound, Excon::Errors::NotFound
|
58
64
|
raise NotFoundError, $!.message, $!.backtrace
|
59
65
|
end
|
60
66
|
|
61
67
|
def connection
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
opts = options.dup
|
69
|
+
opts.delete(:directory)
|
70
|
+
opts.delete(:public)
|
71
|
+
opts[:connection_options] ||= default_connection_options
|
72
|
+
@connection ||= Fog::Storage.new(opts)
|
66
73
|
end
|
67
74
|
|
68
75
|
def directory_name
|
69
76
|
options[:directory]
|
70
77
|
end
|
71
78
|
|
79
|
+
# TODO: Add file bodies if we think it's worth it
|
80
|
+
def files(prefix = '')
|
81
|
+
full_list = []
|
82
|
+
|
83
|
+
directory.files.all(:prefix => prefix).each do |file|
|
84
|
+
full_list.push(
|
85
|
+
File.new(file.identity,
|
86
|
+
:content_type => file.content_type,
|
87
|
+
:stored_in => [self],
|
88
|
+
:last_update_ts => file.last_modified
|
89
|
+
)
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
full_list
|
94
|
+
end
|
95
|
+
|
72
96
|
def directory
|
73
97
|
@directory ||= lookup_directory || create_directory
|
74
98
|
end
|
75
99
|
|
76
100
|
protected
|
77
101
|
|
102
|
+
def default_connection_options
|
103
|
+
{
|
104
|
+
retry_limit: 0,
|
105
|
+
retry_interval: 0
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
78
109
|
def aws_host
|
79
110
|
case options[:region]
|
80
111
|
when nil, 'us-east-1'
|
@@ -22,7 +22,11 @@ module RemoteFiles
|
|
22
22
|
|
23
23
|
def store!(file)
|
24
24
|
content = file.content.respond_to?(:read) ? file.content.read : file.content
|
25
|
-
data[file.identifier] = { :content => content, :content_type => file.content_type}
|
25
|
+
data[file.identifier] = { :content => content, :content_type => file.content_type, :last_update_ts => file.last_update_ts}
|
26
|
+
end
|
27
|
+
|
28
|
+
def copy_to_store!(file, target_store)
|
29
|
+
target_store.data[file.identifier] = data[file.identifier]
|
26
30
|
end
|
27
31
|
|
28
32
|
def retrieve!(identifier)
|
@@ -31,10 +35,23 @@ module RemoteFiles
|
|
31
35
|
File.new(identifier,
|
32
36
|
:content => data[identifier][:content],
|
33
37
|
:content_type => data[identifier][:content_type],
|
38
|
+
:last_update_ts => data[identifier][:last_update_ts],
|
34
39
|
:stored_in => [self]
|
35
40
|
)
|
36
41
|
end
|
37
42
|
|
43
|
+
def files(prefix = '')
|
44
|
+
@data.reject do |identifier|
|
45
|
+
!identifier.start_with? prefix
|
46
|
+
end.map do |identifier, data|
|
47
|
+
File.new(identifier,
|
48
|
+
:content_type => data[:content_type],
|
49
|
+
:last_update_ts => data[:last_update_ts],
|
50
|
+
:stored_in => [self]
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
38
55
|
def directory_name
|
39
56
|
self.identifier.to_s
|
40
57
|
end
|
data/lib/remote_files/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mick Staugaard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-aws
|
@@ -59,7 +59,7 @@ files:
|
|
59
59
|
- lib/remote_files/version.rb
|
60
60
|
homepage: https://github.com/zendesk/remote_files
|
61
61
|
licenses:
|
62
|
-
- Apache
|
62
|
+
- Apache-2.0
|
63
63
|
metadata: {}
|
64
64
|
post_install_message:
|
65
65
|
rdoc_options: []
|
@@ -76,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
|
80
|
-
rubygems_version: 2.7.6
|
79
|
+
rubygems_version: 3.0.3.1
|
81
80
|
signing_key:
|
82
81
|
specification_version: 4
|
83
82
|
summary: The purpose of the library is to implement a simple interface for uploading
|