eco-helpers 2.7.21 → 2.7.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -3
- data/lib/eco/api/common/session/file_manager.rb +67 -29
- data/lib/eco/api/common/version_patches/exception.rb +5 -0
- data/lib/eco/data/files/helpers.rb +7 -5
- data/lib/eco/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d522c29136b4722235f8dbf8349d7328ba7ebe90f77d5fecf15a03a049cc8fe
|
4
|
+
data.tar.gz: b2529b04d22fcc9f013366c07a5bb7905c8d6154af97c4d235fafc1f0bf6452b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 822b1359de0c56118ed2e8e564a54c1119a2bb7597373c029cc72e3f808b3fbd94853a8eced013033613f77b0cfb0c47983e4e03e60e928e30bb6084096d9250
|
7
|
+
data.tar.gz: f32a7ad2a927015c1a2a1b0642f379c1014231db7a2aea00187bf690584a738c7f6770ba361422eeecbf097f2b760c6c6ee502b8c6ca5d790354cef13bf58f26
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [2.7.
|
5
|
+
## [2.7.24] - 2024-07-xx
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
@@ -10,14 +10,31 @@ All notable changes to this project will be documented in this file.
|
|
10
10
|
|
11
11
|
### Fixed
|
12
12
|
|
13
|
-
## [2.7.
|
13
|
+
## [2.7.23] - 2024-07-29
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
- Filename and path scoping
|
18
|
+
|
19
|
+
## [2.7.22] - 2024-07-26
|
14
20
|
|
15
21
|
### Added
|
16
22
|
|
17
|
-
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- Patch on exception: to show cause
|
26
|
+
- `Eco::Common::Session::FileManager`
|
27
|
+
- `load_json` prevent avoidable memory leaks
|
28
|
+
- `save_json` prevent avoidable memory leaks
|
29
|
+
|
30
|
+
### Fixed
|
18
31
|
|
19
32
|
## [2.7.21] - 2024-07-13
|
20
33
|
|
34
|
+
### Added
|
35
|
+
|
36
|
+
- Ability to skip GraphQL schema fetch (`GRAPHQL_FETCH_SCHEMA`)
|
37
|
+
|
21
38
|
### Changed
|
22
39
|
|
23
40
|
- `-clean-unknown-tags` case
|
@@ -3,7 +3,6 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module Session
|
5
5
|
class FileManager
|
6
|
-
|
7
6
|
include Eco::Data::Files
|
8
7
|
|
9
8
|
attr_reader :dir, :dir_path
|
@@ -11,18 +10,17 @@ module Eco
|
|
11
10
|
|
12
11
|
def initialize(init = {}, enviro: nil)
|
13
12
|
@enviro = enviro
|
14
|
-
init
|
13
|
+
init = @enviro.config if @enviro && init.empty?
|
14
|
+
|
15
15
|
@timestamp_pattern = init.files.timestamp_pattern || DEFAULT_TIMESTAMP_PATTERN
|
16
|
-
self.dir_path
|
16
|
+
self.dir_path = init.working_directory || Dir.pwd
|
17
17
|
end
|
18
18
|
|
19
19
|
def dir_path=(value)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
logger.error("could not create or make any sense of directory '#{value}': #{e.to_s}")
|
25
|
-
end
|
20
|
+
@dir = Eco::Data::Files::Directory.new(value)
|
21
|
+
@dir_path = @dir.create
|
22
|
+
rescue StandardError => err
|
23
|
+
logger.error("could not create or make any sense of directory '#{value}': #{err}")
|
26
24
|
end
|
27
25
|
|
28
26
|
def logger
|
@@ -40,53 +38,93 @@ module Eco
|
|
40
38
|
|
41
39
|
def file_content(filename, mode: nil)
|
42
40
|
file = dir.file(filename, should_exist: true)
|
43
|
-
|
41
|
+
|
42
|
+
unless file
|
44
43
|
logger.error("Can't read from file '#{filename}' because it does not exist.")
|
45
44
|
return nil
|
46
45
|
end
|
46
|
+
|
47
47
|
logger.debug("Reading from file '#{file}'")
|
48
48
|
mode ? File.read(file, mode: mode) : File.read(file)
|
49
49
|
end
|
50
50
|
|
51
51
|
def load_json(filename)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
raise e
|
52
|
+
file = dir.file(filename, should_exist: true)
|
53
|
+
|
54
|
+
unless file
|
55
|
+
logger.error("Can't read from file '#{filename}' because it does not exist.")
|
56
|
+
return nil
|
58
57
|
end
|
59
|
-
|
58
|
+
|
59
|
+
fd = File.open(file)
|
60
|
+
JSON.load fd # rubocop:disable Security/JSONLoad
|
61
|
+
rescue JSON::ParserError => e
|
62
|
+
pp "Parsing error on file #{file}"
|
63
|
+
raise e
|
64
|
+
ensure
|
65
|
+
fd&.close
|
60
66
|
end
|
61
67
|
|
62
68
|
def touch(filename, modifier = :no_stamp, mode: :string)
|
63
69
|
save("", filename, modifier, mode: mode)
|
64
70
|
end
|
65
71
|
|
66
|
-
def
|
67
|
-
|
68
|
-
file = FileManager.timestamp_file(file) if modifier == :timestamp
|
69
|
-
mode = (mode == :binary) ? 'wb' : 'w'
|
72
|
+
def save_json(data, filename, modifier = :no_stamp)
|
73
|
+
return save(data.to_json, filename, modifier) unless data.is_a?(Array)
|
70
74
|
|
71
|
-
|
75
|
+
file = filename_for(filename, modifier)
|
76
|
+
FileManager.create_directory(
|
77
|
+
FileManager.file_fullpath(file)
|
78
|
+
)
|
72
79
|
|
73
80
|
logger.debug("Writting to file '#{file}'")
|
74
|
-
|
75
|
-
|
81
|
+
|
82
|
+
mode = mode == :binary ? 'wb' : 'w'
|
83
|
+
|
84
|
+
File.open(file, mode) do |fd|
|
85
|
+
first = true
|
86
|
+
|
87
|
+
fd << '['
|
88
|
+
data.each do |elem|
|
89
|
+
fd << "," unless first
|
90
|
+
first = false
|
91
|
+
|
92
|
+
fd << elem.to_json
|
93
|
+
end
|
94
|
+
fd << ']'
|
95
|
+
end
|
96
|
+
|
97
|
+
file
|
76
98
|
end
|
77
99
|
|
78
|
-
def
|
79
|
-
|
100
|
+
def save(content, filename, modifier = :no_stamp, mode: :string)
|
101
|
+
file = filename_for(filename, modifier)
|
102
|
+
FileManager.create_directory(
|
103
|
+
FileManager.file_fullpath(file)
|
104
|
+
)
|
105
|
+
|
106
|
+
logger.debug("Writting to file '#{file}'")
|
107
|
+
|
108
|
+
mode = mode == :binary ? 'wb' : 'w'
|
109
|
+
File.open(file, mode) { |fd| fd << content }
|
110
|
+
file
|
80
111
|
end
|
81
112
|
|
82
113
|
# if the file does not exist, it creates it
|
83
114
|
def append(content, filename, mode: :string)
|
84
115
|
file = dir.file(filename)
|
85
|
-
mode = (mode == :binary) ? 'ab' : 'a'
|
86
116
|
|
87
117
|
logger.debug("Appending to file '#{file}'")
|
88
|
-
|
89
|
-
|
118
|
+
|
119
|
+
mode = mode == :binary ? 'ab' : 'a'
|
120
|
+
File.open(file, mode) { |fd| fd << "#{content}\n" }
|
121
|
+
file
|
122
|
+
end
|
123
|
+
|
124
|
+
def filename_for(filename, modifier = :no_stamp)
|
125
|
+
file = dir.file(filename)
|
126
|
+
file = FileManager.timestamp_file(file) if modifier == :timestamp
|
127
|
+
file
|
90
128
|
end
|
91
129
|
end
|
92
130
|
end
|
@@ -12,6 +12,11 @@ class ::Exception
|
|
12
12
|
msg << "#{" " * 8}#{i + 1}: from #{bt}"
|
13
13
|
end
|
14
14
|
|
15
|
+
unless cause.nil?
|
16
|
+
msg << "\nCAUSE:"
|
17
|
+
msg << cause.patch_full_message(trace_count: trace_count)
|
18
|
+
end
|
19
|
+
|
15
20
|
msg.join("\n")
|
16
21
|
rescue StandardError => e
|
17
22
|
puts "Something is wrong with 'patch_full_message': #{e}"
|
@@ -54,19 +54,21 @@ module Eco
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def file_name(fullname)
|
57
|
+
return nil unless fullname
|
58
|
+
|
57
59
|
File.basename(fullname)
|
58
60
|
end
|
59
61
|
|
60
62
|
def file_basename(fullname)
|
61
|
-
|
62
|
-
end
|
63
|
+
return nil unless fullname
|
63
64
|
|
64
|
-
|
65
|
-
File.dirname(fullname)
|
65
|
+
File.basename(fullname, File.extname(fullname))
|
66
66
|
end
|
67
67
|
|
68
68
|
def file_fullpath(fullname)
|
69
|
-
|
69
|
+
return nil unless fullname
|
70
|
+
|
71
|
+
File.dirname(File.expand_path(fullname))
|
70
72
|
end
|
71
73
|
|
72
74
|
def file_exists?(file)
|
data/lib/eco/version.rb
CHANGED