eac_fs 0.1.0 → 0.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/eac_fs/cache.rb +64 -0
- data/lib/eac_fs/cached_download.rb +39 -0
- data/lib/eac_fs/file_info.rb +5 -0
- data/lib/eac_fs/patches/module/fs_cache.rb +10 -0
- data/lib/eac_fs/patches/module.rb +4 -0
- data/lib/eac_fs/patches/object/fs_cache.rb +10 -0
- data/lib/eac_fs/patches/object.rb +4 -0
- data/lib/eac_fs/patches/pathname/info.rb +12 -0
- data/lib/eac_fs/patches/pathname.rb +4 -0
- data/lib/eac_fs/patches.rb +4 -0
- data/lib/eac_fs/version.rb +1 -1
- metadata +16 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f84f3e6bee2753e30079a3e79cf4d8ad3568b59dfeac360f1de73d2ca34162d5
|
4
|
+
data.tar.gz: 184ab1296d60754f52dc2d598dec9b18871b1024dde617b3b2cac3d8b50c1490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c1b1a320116205e2c690564bdd3d6aa78451a0b26ef3feeb8a5cddf76b6a96e427e89bc5db02fd535b10453b61d01edd6211e075a2e9819b9f41bef809d1203
|
7
|
+
data.tar.gz: f4bc08f798e701a06a6dadf703eeb6d0c4c5a21c25cb95c5946b6aaf40ae13f9a015a8cb8ac6ffaac96abffefe71dc25e2bf9f6a8970bb2a149ce552306ab4f6
|
data/lib/eac_fs/cache.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module EacFs
|
7
|
+
class Cache
|
8
|
+
enable_context
|
9
|
+
|
10
|
+
CONTENT_FILE_NAME = '__content__'
|
11
|
+
|
12
|
+
attr_reader :path
|
13
|
+
|
14
|
+
def initialize(*path_parts)
|
15
|
+
raise ArgumentError, "\"#{path_parts}\" is empty" if path_parts.empty?
|
16
|
+
|
17
|
+
@path = ::File.expand_path(::File.join(*path_parts.map(&:to_s)))
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear
|
21
|
+
return unless cached?
|
22
|
+
|
23
|
+
::File.unlink(content_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def read
|
27
|
+
return nil unless cached?
|
28
|
+
|
29
|
+
::File.read(content_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def read_or_cache
|
33
|
+
write(yield) unless cached?
|
34
|
+
|
35
|
+
read
|
36
|
+
end
|
37
|
+
|
38
|
+
def write(value)
|
39
|
+
assert_directory_on_path
|
40
|
+
::File.write(content_path, value)
|
41
|
+
value
|
42
|
+
end
|
43
|
+
|
44
|
+
def child(*child_path_parts)
|
45
|
+
self.class.new(path, *child_path_parts)
|
46
|
+
end
|
47
|
+
|
48
|
+
def cached?
|
49
|
+
::File.exist?(content_path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def content_path
|
53
|
+
::File.join(path, CONTENT_FILE_NAME)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def assert_directory_on_path
|
59
|
+
raise "#{path} is a file" if ::File.file?(path)
|
60
|
+
|
61
|
+
::FileUtils.mkdir_p(path)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_fs/patches'
|
4
|
+
require 'eac_ruby_utils/fs/temp'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
class CachedDownload
|
8
|
+
attr_reader :url, :fs_cache
|
9
|
+
|
10
|
+
def initialize(url, parent_fs_cache = nil)
|
11
|
+
@url = url
|
12
|
+
@fs_cache = (parent_fs_cache || fs_cache).child(url.parameterize)
|
13
|
+
end
|
14
|
+
|
15
|
+
def assert
|
16
|
+
download unless fs_cache.cached?
|
17
|
+
end
|
18
|
+
|
19
|
+
def download
|
20
|
+
::EacRubyUtils::Fs::Temp.on_file do |temp|
|
21
|
+
download_to(temp)
|
22
|
+
fs_cache.content_path.to_pathname.dirname.mkpath
|
23
|
+
::FileUtils.mv(temp.to_path, fs_cache.content_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def path
|
28
|
+
fs_cache.content_path.to_pathname
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def download_to(local_file)
|
34
|
+
::URI.parse(url).open do |remote|
|
35
|
+
local_file.open('wb') { |handle| handle.write(remote.read) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/eac_fs/file_info.rb
CHANGED
@@ -6,6 +6,9 @@ require 'filemagic'
|
|
6
6
|
|
7
7
|
module EacFs
|
8
8
|
class FileInfo
|
9
|
+
UNKNOWN_CONTENT_TYPE_STRING = 'application/octet-stream'
|
10
|
+
UNKNOWN_CONTENT_TYPE = ::ContentType.parse(UNKNOWN_CONTENT_TYPE_STRING)
|
11
|
+
|
9
12
|
enable_simple_cache
|
10
13
|
attr_reader :magic_string
|
11
14
|
|
@@ -19,6 +22,8 @@ module EacFs
|
|
19
22
|
|
20
23
|
def content_type_uncached
|
21
24
|
::ContentType.parse(magic_string)
|
25
|
+
rescue ::Parslet::ParseFailed
|
26
|
+
UNKNOWN_CONTENT_TYPE
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
data/lib/eac_fs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_fs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Put here the authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: content-type
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.70'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.70'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ruby-filemagic
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.3'
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
executables: []
|
@@ -73,7 +73,16 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- lib/eac_fs.rb
|
76
|
+
- lib/eac_fs/cache.rb
|
77
|
+
- lib/eac_fs/cached_download.rb
|
76
78
|
- lib/eac_fs/file_info.rb
|
79
|
+
- lib/eac_fs/patches.rb
|
80
|
+
- lib/eac_fs/patches/module.rb
|
81
|
+
- lib/eac_fs/patches/module/fs_cache.rb
|
82
|
+
- lib/eac_fs/patches/object.rb
|
83
|
+
- lib/eac_fs/patches/object/fs_cache.rb
|
84
|
+
- lib/eac_fs/patches/pathname.rb
|
85
|
+
- lib/eac_fs/patches/pathname/info.rb
|
77
86
|
- lib/eac_fs/version.rb
|
78
87
|
homepage:
|
79
88
|
licenses: []
|
@@ -93,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
102
|
- !ruby/object:Gem::Version
|
94
103
|
version: '0'
|
95
104
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.1.6
|
97
106
|
signing_key:
|
98
107
|
specification_version: 4
|
99
108
|
summary: Put here de description.
|