eac_fs 0.2.0 → 0.3.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/cache.rb +64 -0
- data/lib/eac_fs/patches/module/fs_cache.rb +10 -0
- data/lib/eac_fs/patches/module.rb +4 -0
- data/lib/eac_fs/patches/object/fs_cache.rb +10 -0
- data/lib/eac_fs/patches/object.rb +4 -0
- data/lib/eac_fs/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42046162cfd331397663078e9dbd58c38e5fd5d05520afe4652380166d0d1b51
|
4
|
+
data.tar.gz: 8123ecd08337c318867ade46153aad2cd6abf552a0dd0d1f74392b9923652833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed56297284fba8ee9639b10fc83fb6c1c5a4df5de4796609f3fb18020e1ed9184b408daeaf3562cb812bb01f5f5fcd174bab33f5570be2b1a69a322e0c09a522
|
7
|
+
data.tar.gz: f73d940b0e962401e4465bd3c206ee83ec926ab5620591bffae110b251f92f11bfaeb0ac745a725f00370b65ada96e68d78ba880bcd78b76660643dabcd4f914
|
data/lib/eac_fs/cache.rb
ADDED
@@ -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
|
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.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-
|
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
|