eac_fs 0.3.0 → 0.7.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/eac_fs/cached_download.rb +39 -0
- data/lib/eac_fs/file_info.rb +5 -0
- data/lib/eac_fs/patches/object/fs_cache.rb +8 -1
- data/lib/eac_fs/traversable.rb +45 -0
- data/lib/eac_fs/traverser.rb +76 -0
- data/lib/eac_fs/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a50d926bb9f417c771ef1604225125d9392a0cf9f23bcb254181439d533e9ebb
|
4
|
+
data.tar.gz: 075f54f4bf0fe9fe433cf5d8b7a71a56aeab554639e492c10d9c537be90e3b27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e494322e83221cc0379f91dbb7b2d9c33c3cf6eb63d272f7b6678966b9350cd48fdde7adc1dab95cba5c4cdf675b575f5104c590573802be17c86c443caedd29
|
7
|
+
data.tar.gz: 5b807d751bdd3ee8c9e7650635e3cf74a70500c7f58c43543d6c962b82bc962bc79ed02121860d2835bb771b1f6d06eec7e3f9b99aea616b4b42bb8b05ff29f3
|
@@ -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
|
@@ -5,6 +5,13 @@ require 'eac_fs/patches/module/fs_cache'
|
|
5
5
|
class Object
|
6
6
|
# @return [EacFs::Cache]
|
7
7
|
def fs_cache
|
8
|
-
|
8
|
+
oid = fs_cache_object_id
|
9
|
+
oid = [oid.to_s] unless oid.is_a?(::Enumerable)
|
10
|
+
oid.inject(self.class.fs_cache) { |a, e| a.child(e.to_s) }
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String, Array<String>]
|
14
|
+
def fs_cache_object_id
|
15
|
+
raise 'Abstract method hit'
|
9
16
|
end
|
10
17
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_fs/traverser'
|
4
|
+
|
5
|
+
module EacFs
|
6
|
+
module Traversable
|
7
|
+
PROP_METHOD_PREFIX = 'traverser_'
|
8
|
+
BOOLEAN_PROPS = %i[hidden_directories recursive sort].freeze
|
9
|
+
PATH_PROPS = %i[check_directory check_file].freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def prop_method_name(prop)
|
13
|
+
"#{PROP_METHOD_PREFIX}#{prop}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
PATH_PROPS.each do |method|
|
18
|
+
define_method(::EacFs::Traversable.prop_method_name(method)) do |_path|
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
BOOLEAN_PROPS.each do |method|
|
24
|
+
define_method(::EacFs::Traversable.prop_method_name(method)) do
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
define_method("#{::EacFs::Traversable.prop_method_name(method)}?") do
|
29
|
+
send(method_name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def traverser_check_path(path)
|
34
|
+
traverser_new.check_path(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def traverser_new
|
38
|
+
r = ::EacFs::Traverser.new
|
39
|
+
(BOOLEAN_PROPS + PATH_PROPS).each do |prop|
|
40
|
+
r.send("#{prop}=", method(::EacFs::Traversable.prop_method_name(prop)))
|
41
|
+
end
|
42
|
+
r
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacFs
|
4
|
+
class Traverser
|
5
|
+
attr_accessor :check_directory, :check_file, :recursive, :hidden_directories, :sort
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
options.each do |accessor, value|
|
9
|
+
send("#{accessor}=", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_path(path)
|
14
|
+
path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname)
|
15
|
+
internal_check_path(path, 0)
|
16
|
+
end
|
17
|
+
|
18
|
+
def hidden_directories?
|
19
|
+
boolean_value(hidden_directories)
|
20
|
+
end
|
21
|
+
|
22
|
+
def recursive?
|
23
|
+
boolean_value(recursive)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sort?
|
27
|
+
boolean_value(sort)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def boolean_value(source_value)
|
33
|
+
source_value = source_value.call if source_value.respond_to?(:call)
|
34
|
+
source_value ? true : false
|
35
|
+
end
|
36
|
+
|
37
|
+
def each_child(dir, &block)
|
38
|
+
if sort?
|
39
|
+
dir.each_child.sort_by { |p| [p.to_s] }.each(&block)
|
40
|
+
else
|
41
|
+
dir.each_child(&block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_directory?(level)
|
46
|
+
level.zero? || recursive?
|
47
|
+
end
|
48
|
+
|
49
|
+
def inner_check_directory(dir, level)
|
50
|
+
return unless process_directory?(level)
|
51
|
+
|
52
|
+
user_check_directory(dir)
|
53
|
+
each_child(dir) do |e|
|
54
|
+
next unless !e.basename.to_s.start_with?('.') || hidden_directories?
|
55
|
+
|
56
|
+
internal_check_path(e, level + 1)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def internal_check_path(path, level)
|
61
|
+
if path.file?
|
62
|
+
user_check_file(path)
|
63
|
+
elsif path.directory?
|
64
|
+
inner_check_directory(path, level)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def user_check_file(path)
|
69
|
+
check_file&.call(path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def user_check_directory(path)
|
73
|
+
check_directory&.call(path)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
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.7.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-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: content-type
|
@@ -74,6 +74,7 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- lib/eac_fs.rb
|
76
76
|
- lib/eac_fs/cache.rb
|
77
|
+
- lib/eac_fs/cached_download.rb
|
77
78
|
- lib/eac_fs/file_info.rb
|
78
79
|
- lib/eac_fs/patches.rb
|
79
80
|
- lib/eac_fs/patches/module.rb
|
@@ -82,6 +83,8 @@ files:
|
|
82
83
|
- lib/eac_fs/patches/object/fs_cache.rb
|
83
84
|
- lib/eac_fs/patches/pathname.rb
|
84
85
|
- lib/eac_fs/patches/pathname/info.rb
|
86
|
+
- lib/eac_fs/traversable.rb
|
87
|
+
- lib/eac_fs/traverser.rb
|
85
88
|
- lib/eac_fs/version.rb
|
86
89
|
homepage:
|
87
90
|
licenses: []
|