eac_fs 0.8.1 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d10da0054341f15b13229c38ee23f562d031eed02e1551e1672d76353819e57
4
- data.tar.gz: ef5ce5e89c868acd751620330a295bca3382e1502a75eb4e071e4f3ce9b2a57d
3
+ metadata.gz: 8851f1408994cf816ba9352954d7ef9a8858e8581434f5d14e917f7b9d3dd6bb
4
+ data.tar.gz: b31e40c894d8cb96cc5d1eae42789e980c4bfe849f47e9c2d0aac8d870b919ef
5
5
  SHA512:
6
- metadata.gz: f5f015ff3178af6b1b66912655f30694853c49ce7f18e92e977a7ec3c7befc90bc637522eea84a407f72563d8d766b40c1497f41ce76c5a23ebdeea21c27931a
7
- data.tar.gz: 5d6744fae96e6ea41bc8e17559924a80dc7d8e2a1081db464145a9fedd16d535d16bf05d4a871d6981b249fe5c7437d05d5f555a7a47203651a0e4756b3e3d35
6
+ metadata.gz: 37c02d3e22a2bfd5ffb77014bcca94555e1a41bec612a01d3c306fda460cc29468627ed0b38c508aaae8585d1c7e6e8ec8223c6058bab77008d5f2185c029cf3
7
+ data.tar.gz: 89405f8115a4479a59953cef8c3df475c052bd40927941b1e6d527c7619e96c90c857dc85931022b0a422b18629feccd14c6e76f76f1dc9d2141c03098038178
@@ -3,17 +3,17 @@
3
3
  require 'eac_fs/patches'
4
4
  require 'eac_ruby_utils/fs/temp'
5
5
 
6
- module Avm
6
+ module EacFs
7
7
  class CachedDownload
8
8
  attr_reader :url, :fs_cache
9
9
 
10
10
  def initialize(url, parent_fs_cache = nil)
11
11
  @url = url
12
- @fs_cache = (parent_fs_cache || fs_cache).child(url.parameterize)
12
+ @fs_cache = (parent_fs_cache || fs_cache).child(url.to_s.parameterize)
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
@@ -13,6 +13,10 @@ module EacFs
13
13
 
14
14
  delegate :remove, to: :file
15
15
 
16
+ def clean
17
+ file.truncate(0) if file.exist?
18
+ end
19
+
16
20
  def file_size
17
21
  file.file? ? file.size : 0
18
22
  end
data/lib/eac_fs/logs.rb CHANGED
@@ -23,6 +23,11 @@ module EacFs
23
23
  self
24
24
  end
25
25
 
26
+ # @return [EacFs::Logs]
27
+ def clean_all
28
+ log_set.values.each(&:clean)
29
+ end
30
+
26
31
  # @return [EacFs::Logs]
27
32
  def remove_all
28
33
  log_set.each_key { |label| remove(label) }
@@ -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
- def read_or_cache
33
- write(yield) unless cached?
30
+ def read_or_store
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.8.1'
4
+ VERSION = '0.11.1'
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.8.1
4
+ version: 0.11.1
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-12-08 00:00:00.000000000 Z
11
+ date: 2022-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content-type
@@ -73,8 +73,8 @@ 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
79
  - lib/eac_fs/logs.rb
80
80
  - lib/eac_fs/logs/file.rb
@@ -85,6 +85,7 @@ files:
85
85
  - lib/eac_fs/patches/object/fs_cache.rb
86
86
  - lib/eac_fs/patches/pathname.rb
87
87
  - lib/eac_fs/patches/pathname/info.rb
88
+ - lib/eac_fs/storage_tree.rb
88
89
  - lib/eac_fs/traversable.rb
89
90
  - lib/eac_fs/traverser.rb
90
91
  - lib/eac_fs/version.rb