eac_fs 0.7.0 → 0.8.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/logs/file.rb +50 -0
- data/lib/eac_fs/logs.rb +59 -0
- data/lib/eac_fs/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcb1c3229305e0ad12c014a54395563e8550d6f140c73e59de2af545e2390e4f
|
4
|
+
data.tar.gz: 4b507f0c4f589b3d686ed93c5de67cba5504d7e73d539e6758ccf1988f443132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2e9da3106b51158639edea495810817dae7e5884d28092b2fd7da4b20990c2d1679dae6d4b8f1765fa28414c8a43a016ee97e91a31a2fc21aa296235d5d99fb
|
7
|
+
data.tar.gz: 679acb700750d0c560b458a4385a41ff26728534f5a92b00885b1d2308f48a1246fb23b510c64e85d99f76c31ae32eed65ad13b225efb5edec7990fd9ebc5c1f
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacFs
|
6
|
+
class Logs
|
7
|
+
class File
|
8
|
+
enable_simple_cache
|
9
|
+
common_constructor :label
|
10
|
+
|
11
|
+
TRUNCATE_DEFAULT_LENGTH = 1000
|
12
|
+
TRUNCATE_APPEND_TEXT = '(...) '
|
13
|
+
|
14
|
+
def file_size
|
15
|
+
file.file? ? file.size : 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def pretty_file_size
|
19
|
+
::Filesize.from("#{file_size} B").pretty
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param length [Integer]
|
23
|
+
# @return [String]
|
24
|
+
def truncate(length = TRUNCATE_DEFAULT_LENGTH)
|
25
|
+
content = file.file? ? file.read.strip : ''
|
26
|
+
return content if content.length <= TRUNCATE_DEFAULT_LENGTH
|
27
|
+
|
28
|
+
TRUNCATE_APPEND_TEXT + content[content.length - length + TRUNCATE_APPEND_TEXT.length,
|
29
|
+
length - TRUNCATE_APPEND_TEXT.length]
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param length [Integer]
|
33
|
+
# @return [String]
|
34
|
+
def truncate_with_label(length = TRUNCATE_DEFAULT_LENGTH)
|
35
|
+
header = [label, file, pretty_file_size].join(' / ')
|
36
|
+
return ">>> #{header} (Not found) <<<" unless file.file?
|
37
|
+
|
38
|
+
content = truncate(length)
|
39
|
+
content.blank? ? ">>> #{header} (Blank) <<<" : ">>> #{header}\n#{content}\n<<< #{header}\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
# @return [EacRubyUtils::Fs::Temp::File
|
45
|
+
def file_uncached
|
46
|
+
::EacRubyUtils::Fs::Temp.file
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/eac_fs/logs.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/fs/temp'
|
5
|
+
require 'filesize'
|
6
|
+
|
7
|
+
module EacFs
|
8
|
+
class Logs
|
9
|
+
require_sub __FILE__
|
10
|
+
|
11
|
+
# @param label [Symbol]
|
12
|
+
# @return [EacRubyUtils::Fs::Temp::File]
|
13
|
+
def [](label)
|
14
|
+
log_set.fetch(sanitize_label(label)).file
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param label [Symbol]
|
18
|
+
# @return [EacFs::Logs]
|
19
|
+
def add(label)
|
20
|
+
file = ::EacFs::Logs::File.new(sanitize_label(label))
|
21
|
+
log_set[file.label] = file
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [EacFs::Logs]
|
27
|
+
def remove_all
|
28
|
+
log_set.each_key { |label| remove(label) }
|
29
|
+
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param label [Symbol]
|
34
|
+
def remove(label)
|
35
|
+
log_set.fetch(sanitize_label(label)).remove
|
36
|
+
log_set.delete(sanitize_label(label))
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param length [Integer]
|
40
|
+
# @return [String]
|
41
|
+
def truncate_all(length = ::EacFs::Logs::File::TRUNCATE_DEFAULT_LENGTH)
|
42
|
+
"Files: #{log_set.length}\n" +
|
43
|
+
log_set.values.map { |file| file.truncate_with_label(length) }.join
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# @param label [Object]
|
49
|
+
# @return [Symbol]
|
50
|
+
def sanitize_label(label)
|
51
|
+
label.to_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Hash<Symbol, EacFs::Logs::File>]
|
55
|
+
def log_set
|
56
|
+
@log_set ||= {}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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.8.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-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: content-type
|
@@ -76,6 +76,8 @@ files:
|
|
76
76
|
- lib/eac_fs/cache.rb
|
77
77
|
- lib/eac_fs/cached_download.rb
|
78
78
|
- lib/eac_fs/file_info.rb
|
79
|
+
- lib/eac_fs/logs.rb
|
80
|
+
- lib/eac_fs/logs/file.rb
|
79
81
|
- lib/eac_fs/patches.rb
|
80
82
|
- lib/eac_fs/patches/module.rb
|
81
83
|
- lib/eac_fs/patches/module/fs_cache.rb
|