eac_fs 0.2.0 → 0.3.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: 158a0fb4e5435bf5998dcc7750acdcb419a5c51c8215a3cb2abb2c0dc1f09e5c
4
- data.tar.gz: 8688b52689cdeecd682d75687baaada255c080791a0794dc93f86d24895c5f85
3
+ metadata.gz: 42046162cfd331397663078e9dbd58c38e5fd5d05520afe4652380166d0d1b51
4
+ data.tar.gz: 8123ecd08337c318867ade46153aad2cd6abf552a0dd0d1f74392b9923652833
5
5
  SHA512:
6
- metadata.gz: 4a9f2275e81cf3a815f8dfa0d032da1cc7eabc66c39d055d3e6636a1448b0a1ef8b0276c0bf3846f9ffd615e2dd792494906d9b5fcafb1273bed8eeeb2d047fa
7
- data.tar.gz: 2348049d4da7d34700043d25bb0ee4cd99793a5c062eced10be1864a92adc34ff2b04c5bbc1b042a8f700133c61f3f38aa60c8cc5f97ab75b58fc26693df7b51
6
+ metadata.gz: ed56297284fba8ee9639b10fc83fb6c1c5a4df5de4796609f3fb18020e1ed9184b408daeaf3562cb812bb01f5f5fcd174bab33f5570be2b1a69a322e0c09a522
7
+ data.tar.gz: f73d940b0e962401e4465bd3c206ee83ec926ab5620591bffae110b251f92f11bfaeb0ac745a725f00370b65ada96e68d78ba880bcd78b76660643dabcd4f914
@@ -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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_fs/cache'
4
+
5
+ class Module
6
+ # @return [EacFs::Cache]
7
+ def fs_cache
8
+ ::EacFs::Cache.context.current.child('fs_cache', *name.split('::'))
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_fs/patches/module/fs_cache'
4
+
5
+ class Object
6
+ # @return [EacFs::Cache]
7
+ def fs_cache
8
+ self.class.fs_cache
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacFs
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.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-09-05 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content-type
@@ -73,8 +73,13 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - lib/eac_fs.rb
76
+ - lib/eac_fs/cache.rb
76
77
  - lib/eac_fs/file_info.rb
77
78
  - lib/eac_fs/patches.rb
79
+ - lib/eac_fs/patches/module.rb
80
+ - lib/eac_fs/patches/module/fs_cache.rb
81
+ - lib/eac_fs/patches/object.rb
82
+ - lib/eac_fs/patches/object/fs_cache.rb
78
83
  - lib/eac_fs/patches/pathname.rb
79
84
  - lib/eac_fs/patches/pathname/info.rb
80
85
  - lib/eac_fs/version.rb