remote_files 3.3.0 → 3.4.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 +4 -4
- data/lib/remote_files/abstract_store.rb +8 -0
- data/lib/remote_files/file.rb +4 -3
- data/lib/remote_files/file_store.rb +25 -3
- data/lib/remote_files/fog_store.rb +24 -1
- data/lib/remote_files/memory_store.rb +18 -1
- data/lib/remote_files/version.rb +1 -1
- metadata +2 -2
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,16 +1,17 @@
|
|
1
1
|
module RemoteFiles
|
2
2
|
class File
|
3
|
-
attr_reader :content, :content_type, :identifier, :stored_in, :configuration, :populate_stored_in
|
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, :populate_stored_in]
|
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]
|
@@ -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
|
@@ -70,6 +76,23 @@ module RemoteFiles
|
|
70
76
|
options[:directory]
|
71
77
|
end
|
72
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
|
+
|
73
96
|
def directory
|
74
97
|
@directory ||= lookup_directory || create_directory
|
75
98
|
end
|
@@ -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: 2022-05-
|
11
|
+
date: 2022-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-aws
|