eac_fs 0.7.0 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a50d926bb9f417c771ef1604225125d9392a0cf9f23bcb254181439d533e9ebb
4
- data.tar.gz: 075f54f4bf0fe9fe433cf5d8b7a71a56aeab554639e492c10d9c537be90e3b27
3
+ metadata.gz: e852c4bca2367df238571d8d843e2440fe0c7e91f564dab685f4ea1e5188d7a2
4
+ data.tar.gz: aa31fa42eedb2bb8ed49642dadd57d2c548fca7c484e9d0e766bf3c8712f1f44
5
5
  SHA512:
6
- metadata.gz: e494322e83221cc0379f91dbb7b2d9c33c3cf6eb63d272f7b6678966b9350cd48fdde7adc1dab95cba5c4cdf675b575f5104c590573802be17c86c443caedd29
7
- data.tar.gz: 5b807d751bdd3ee8c9e7650635e3cf74a70500c7f58c43543d6c962b82bc962bc79ed02121860d2835bb771b1f6d06eec7e3f9b99aea616b4b42bb8b05ff29f3
6
+ metadata.gz: f2f4aabd8d31321f475f67545db56fa49fdc54bf46fcb007478589e1d365fb45050dc0f988536c7e3232b8839d9b3a72a1c2ce612bfcc1ddd4a0481cc000610a
7
+ data.tar.gz: c89c848cb937e1bb100584d7974180a7dd8725d8b233837ee04ae12f649fd424966a7b82e29dd2fdb1f64886e3a9f18b844a46e42cfbdd191a9197336f180860
@@ -13,7 +13,7 @@ module Avm
13
13
  end
14
14
 
15
15
  def assert
16
- download unless fs_cache.cached?
16
+ download unless fs_cache.stored?
17
17
  end
18
18
 
19
19
  def download
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/context'
5
+
6
+ module EacFs
7
+ class Contexts
8
+ TYPES = %i[cache config data].freeze
9
+
10
+ class << self
11
+ TYPES.each do |type|
12
+ class_eval <<~CODE, __FILE__, __LINE__ + 1
13
+ # @return [EacRubyUtils::Context<EacFs::StorageTree>]
14
+ def #{type}
15
+ @#{type} ||= ::EacRubyUtils::Context.new
16
+ end
17
+ CODE
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,56 @@
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
+ delegate :remove, to: :file
15
+
16
+ def clean
17
+ file.truncate(0) if file.exist?
18
+ end
19
+
20
+ def file_size
21
+ file.file? ? file.size : 0
22
+ end
23
+
24
+ def pretty_file_size
25
+ ::Filesize.from("#{file_size} B").pretty
26
+ end
27
+
28
+ # @param length [Integer]
29
+ # @return [String]
30
+ def truncate(length = TRUNCATE_DEFAULT_LENGTH)
31
+ content = file.file? ? file.read.strip : ''
32
+ return content if content.length <= TRUNCATE_DEFAULT_LENGTH
33
+
34
+ TRUNCATE_APPEND_TEXT + content[content.length - length + TRUNCATE_APPEND_TEXT.length,
35
+ length - TRUNCATE_APPEND_TEXT.length]
36
+ end
37
+
38
+ # @param length [Integer]
39
+ # @return [String]
40
+ def truncate_with_label(length = TRUNCATE_DEFAULT_LENGTH)
41
+ header = [label, file, pretty_file_size].join(' / ')
42
+ return ">>> #{header} (Not found) <<<" unless file.file?
43
+
44
+ content = truncate(length)
45
+ content.blank? ? ">>> #{header} (Blank) <<<" : ">>> #{header}\n#{content}\n<<< #{header}\n"
46
+ end
47
+
48
+ protected
49
+
50
+ # @return [EacRubyUtils::Fs::Temp::File
51
+ def file_uncached
52
+ ::EacRubyUtils::Fs::Temp.file
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,64 @@
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 clean_all
28
+ log_set.values.each(&:clean)
29
+ end
30
+
31
+ # @return [EacFs::Logs]
32
+ def remove_all
33
+ log_set.each_key { |label| remove(label) }
34
+
35
+ self
36
+ end
37
+
38
+ # @param label [Symbol]
39
+ def remove(label)
40
+ log_set.fetch(sanitize_label(label)).remove
41
+ log_set.delete(sanitize_label(label))
42
+ end
43
+
44
+ # @param length [Integer]
45
+ # @return [String]
46
+ def truncate_all(length = ::EacFs::Logs::File::TRUNCATE_DEFAULT_LENGTH)
47
+ "Files: #{log_set.length}\n" +
48
+ log_set.values.map { |file| file.truncate_with_label(length) }.join
49
+ end
50
+
51
+ private
52
+
53
+ # @param label [Object]
54
+ # @return [Symbol]
55
+ def sanitize_label(label)
56
+ label.to_sym
57
+ end
58
+
59
+ # @return [Hash<Symbol, EacFs::Logs::File>]
60
+ def log_set
61
+ @log_set ||= {}
62
+ end
63
+ end
64
+ end
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_fs/cache'
3
+ require 'eac_fs/contexts'
4
4
 
5
5
  class Module
6
- # @return [EacFs::Cache]
7
- def fs_cache
8
- ::EacFs::Cache.context.current.child('fs_cache', *name.split('::'))
6
+ ::EacFs::Contexts::TYPES.each do |type|
7
+ method_name = "fs_#{type}"
8
+ class_eval <<~CODE, __FILE__, __LINE__ + 1
9
+ # @return [EacFs::StorageTree]
10
+ def #{method_name}
11
+ ::EacFs::Contexts.#{type}.current.child('#{method_name}', *name.split('::'))
12
+ end
13
+ CODE
9
14
  end
10
15
  end
@@ -1,17 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_fs/contexts'
3
4
  require 'eac_fs/patches/module/fs_cache'
4
5
 
5
6
  class Object
6
- # @return [EacFs::Cache]
7
- def fs_cache
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) }
7
+ ::EacFs::Contexts::TYPES.each do |type|
8
+ class_eval <<~CODE, __FILE__, __LINE__ + 1
9
+ # @return [EacFs::StorageTree]
10
+ def fs_#{type}
11
+ oid = fs_object_id_by_type(:'#{type}')
12
+ oid = [oid.to_s] unless oid.is_a?(::Enumerable)
13
+ oid.inject(self.class.fs_#{type}) { |a, e| a.child(e.to_s) }
14
+ end
15
+ CODE
11
16
  end
12
17
 
13
18
  # @return [String, Array<String>]
14
- def fs_cache_object_id
19
+ def fs_object_id
15
20
  raise 'Abstract method hit'
16
21
  end
22
+
23
+ def fs_object_id_by_type(type)
24
+ method = "fs_#{type}_object_id"
25
+ respond_to?(method) ? send(method) : fs_object_id
26
+ end
17
27
  end
@@ -4,9 +4,7 @@ require 'eac_ruby_utils/core_ext'
4
4
  require 'fileutils'
5
5
 
6
6
  module EacFs
7
- class Cache
8
- enable_context
9
-
7
+ class StorageTree
10
8
  CONTENT_FILE_NAME = '__content__'
11
9
 
12
10
  attr_reader :path
@@ -18,19 +16,19 @@ module EacFs
18
16
  end
19
17
 
20
18
  def clear
21
- return unless cached?
19
+ return unless stored?
22
20
 
23
21
  ::File.unlink(content_path)
24
22
  end
25
23
 
26
24
  def read
27
- return nil unless cached?
25
+ return nil unless stored?
28
26
 
29
27
  ::File.read(content_path)
30
28
  end
31
29
 
32
30
  def read_or_cache
33
- write(yield) unless cached?
31
+ write(yield) unless stored?
34
32
 
35
33
  read
36
34
  end
@@ -45,7 +43,7 @@ module EacFs
45
43
  self.class.new(path, *child_path_parts)
46
44
  end
47
45
 
48
- def cached?
46
+ def stored?
49
47
  ::File.exist?(content_path)
50
48
  end
51
49
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacFs
4
- VERSION = '0.7.0'
4
+ VERSION = '0.10.0'
5
5
  end
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.7.0
4
+ version: 0.10.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-16 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content-type
@@ -73,9 +73,11 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - lib/eac_fs.rb
76
- - lib/eac_fs/cache.rb
77
76
  - lib/eac_fs/cached_download.rb
77
+ - lib/eac_fs/contexts.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
@@ -83,6 +85,7 @@ files:
83
85
  - lib/eac_fs/patches/object/fs_cache.rb
84
86
  - lib/eac_fs/patches/pathname.rb
85
87
  - lib/eac_fs/patches/pathname/info.rb
88
+ - lib/eac_fs/storage_tree.rb
86
89
  - lib/eac_fs/traversable.rb
87
90
  - lib/eac_fs/traverser.rb
88
91
  - lib/eac_fs/version.rb