eac_fs 0.13.0 → 0.15.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/comparator/build.rb +57 -0
- data/lib/eac_fs/comparator.rb +1 -37
- data/lib/eac_fs/core_ext.rb +4 -0
- data/lib/eac_fs/rspec/setup.rb +25 -0
- data/lib/eac_fs/rspec.rb +9 -0
- data/lib/eac_fs/version.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4031986be77f48819eb9af350455fe15bb0abd14cba43d2b25ca25d42928e1db
|
4
|
+
data.tar.gz: aaba495203079260d90c438fa3ab44dc852b33522e2e9858171bd62f613a5d2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb49886283e3c9eb009355e8c56d164f5e719e9fb8e4d22b1501d4fe97cd884e0333cd74ca39145ab77c74ae0a0da0993b1d32620781cc153c06978853f5c5ce
|
7
|
+
data.tar.gz: 104f746db3c183c06163812ef322d75f046aff8b65b9b60a061bd46869bac9447fe11ff2924ee1245d3e43524ec368f35e7c02beda8d6fc9a78f2b21b0da2c31
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacFs
|
6
|
+
class Comparator
|
7
|
+
class Build
|
8
|
+
TRUNCATE_FILE_CONTENT = "__TRUNCATED__\n"
|
9
|
+
|
10
|
+
enable_method_class
|
11
|
+
common_constructor :comparator, :root
|
12
|
+
delegate :rename_files, :truncate_files, to: :comparator
|
13
|
+
|
14
|
+
# @return [Hash]
|
15
|
+
def result
|
16
|
+
build(root)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build(obj)
|
22
|
+
if obj.file?
|
23
|
+
build_file(obj)
|
24
|
+
elsif obj.directory?
|
25
|
+
build_directory(obj)
|
26
|
+
else
|
27
|
+
raise "Unknown filesystem object \"#{obj}\""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param dir [Pathname]
|
32
|
+
# @return [Hash]
|
33
|
+
def build_directory(dir)
|
34
|
+
dir.children.map do |child|
|
35
|
+
[fs_object_basename(child), build(child)]
|
36
|
+
end.to_h
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param file [Pathname]
|
40
|
+
# @return [Hash]
|
41
|
+
def build_file(file)
|
42
|
+
truncate_file?(file) ? TRUNCATE_FILE_CONTENT : file.read
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String]
|
46
|
+
def fs_object_basename(obj)
|
47
|
+
rename_files.inject(obj.basename.to_path) { |a, e| e.apply(a) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def truncate_file?(file)
|
51
|
+
truncate_files.any? do |pattern|
|
52
|
+
file.basename.fnmatch?(pattern)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/eac_fs/comparator.rb
CHANGED
@@ -4,51 +4,15 @@ require 'eac_ruby_utils/core_ext'
|
|
4
4
|
|
5
5
|
module EacFs
|
6
6
|
class Comparator
|
7
|
-
require_sub __FILE__
|
8
|
-
|
9
|
-
TRUNCATE_FILE_CONTENT = "__TRUNCATED__\n"
|
7
|
+
require_sub __FILE__, require_dependency: true
|
10
8
|
|
11
9
|
enable_immutable
|
12
10
|
immutable_accessor :rename_file, :truncate_file, type: :array
|
13
11
|
|
14
|
-
# @return [Hash]
|
15
|
-
def build(obj)
|
16
|
-
if obj.file?
|
17
|
-
build_file(obj)
|
18
|
-
elsif obj.directory?
|
19
|
-
build_directory(obj)
|
20
|
-
else
|
21
|
-
raise "Unknown filesystem object \"#{obj}\""
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
12
|
alias rename_file_push rename_file
|
26
13
|
|
27
14
|
def rename_file(from, to)
|
28
15
|
rename_file_push(::EacFs::Comparator::RenameFile.new(from, to))
|
29
16
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# @param dir [Pathname]
|
34
|
-
# @return [Hash]
|
35
|
-
def build_directory(dir)
|
36
|
-
dir.children.map do |child|
|
37
|
-
[fs_object_basename(child), build(child)]
|
38
|
-
end.to_h
|
39
|
-
end
|
40
|
-
|
41
|
-
# @param file [Pathname]
|
42
|
-
# @return [Hash]
|
43
|
-
def build_file(file)
|
44
|
-
return TRUNCATE_FILE_CONTENT if truncate_files.include?(file.basename.to_path)
|
45
|
-
|
46
|
-
file.read
|
47
|
-
end
|
48
|
-
|
49
|
-
# @return [String]
|
50
|
-
def fs_object_basename(obj)
|
51
|
-
rename_files.inject(obj.basename.to_path) { |a, e| e.apply(a) }
|
52
|
-
end
|
53
17
|
end
|
54
18
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_fs/contexts'
|
5
|
+
require 'eac_fs/storage_tree'
|
6
|
+
require 'eac_ruby_utils/fs/temp'
|
7
|
+
|
8
|
+
module EacFs
|
9
|
+
module Rspec
|
10
|
+
module Setup
|
11
|
+
require_sub __FILE__
|
12
|
+
|
13
|
+
# @return [self]
|
14
|
+
def stub_eac_fs_contexts
|
15
|
+
::EacFs::Contexts::TYPES.each do |type|
|
16
|
+
::EacFs::Contexts.send(type).push(
|
17
|
+
::EacFs::StorageTree.new(::EacRubyUtils::Fs::Temp.directory)
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/eac_fs/rspec.rb
ADDED
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.15.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: 2022-
|
11
|
+
date: 2022-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: content-type
|
@@ -36,20 +36,20 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
39
|
+
version: '0.107'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.
|
42
|
+
version: 0.107.1
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0.
|
49
|
+
version: '0.107'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.
|
52
|
+
version: 0.107.1
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: ruby-filemagic
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,8 +93,10 @@ files:
|
|
93
93
|
- lib/eac_fs.rb
|
94
94
|
- lib/eac_fs/cached_download.rb
|
95
95
|
- lib/eac_fs/comparator.rb
|
96
|
+
- lib/eac_fs/comparator/build.rb
|
96
97
|
- lib/eac_fs/comparator/rename_file.rb
|
97
98
|
- lib/eac_fs/contexts.rb
|
99
|
+
- lib/eac_fs/core_ext.rb
|
98
100
|
- lib/eac_fs/file_info.rb
|
99
101
|
- lib/eac_fs/logs.rb
|
100
102
|
- lib/eac_fs/logs/file.rb
|
@@ -105,6 +107,8 @@ files:
|
|
105
107
|
- lib/eac_fs/patches/object/fs_cache.rb
|
106
108
|
- lib/eac_fs/patches/pathname.rb
|
107
109
|
- lib/eac_fs/patches/pathname/info.rb
|
110
|
+
- lib/eac_fs/rspec.rb
|
111
|
+
- lib/eac_fs/rspec/setup.rb
|
108
112
|
- lib/eac_fs/storage_tree.rb
|
109
113
|
- lib/eac_fs/traversable.rb
|
110
114
|
- lib/eac_fs/traverser.rb
|