eco-helpers 2.7.21 → 2.7.22
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 +4 -4
- data/CHANGELOG.md +7 -4
- data/lib/eco/api/common/session/file_manager.rb +66 -29
- data/lib/eco/api/common/version_patches/exception.rb +5 -0
- 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: 7cc77a4ee2eb9f30b13efc22f5eaedff1b564f9831c3b7f4d9430b80185ffb83
|
4
|
+
data.tar.gz: fbe4135c3c9c08d46c1ee39b1b3de0c28fd2be547243d2137e49517997052d96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f9d81d2a91bf458dadd99e60b15c2e4063e902fa4e9663383367f91a0ad39fdbf4bd4f367a11fa5aef6f9aacfe82ee22161adc4f36ec46781e2d23ef9798168
|
7
|
+
data.tar.gz: 823605e14716575990fcc13db6e538bc7642164b77b889d10fb0b3037bd8a9304751e012ba1fe3229895e0ec1d3585ea69318496a4226df5af18a7c288a42f81
|
data/CHANGELOG.md
CHANGED
@@ -2,22 +2,25 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [2.7.
|
5
|
+
## [2.7.22] - 2024-07-xx
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
9
9
|
### Changed
|
10
10
|
|
11
|
+
- Patch on exception: to show cause
|
12
|
+
- `Eco::Common::Session::FileManager`
|
13
|
+
- `load_json` prevent avoidable memory leaks
|
14
|
+
- `save_json` prevent avoidable memory leaks
|
15
|
+
|
11
16
|
### Fixed
|
12
17
|
|
13
|
-
## [2.7.
|
18
|
+
## [2.7.21] - 2024-07-13
|
14
19
|
|
15
20
|
### Added
|
16
21
|
|
17
22
|
- Ability to skip GraphQL schema fetch (`GRAPHQL_FETCH_SCHEMA`)
|
18
23
|
|
19
|
-
## [2.7.21] - 2024-07-13
|
20
|
-
|
21
24
|
### Changed
|
22
25
|
|
23
26
|
- `-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 => e
|
23
|
+
logger.error("could not create or make any sense of directory '#{value}': #{e.to_s}")
|
26
24
|
end
|
27
25
|
|
28
26
|
def logger
|
@@ -40,53 +38,92 @@ 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
|
+
FileManager.timestamp_file(file) if modifier == :timestamp
|
90
127
|
end
|
91
128
|
end
|
92
129
|
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}"
|
data/lib/eco/version.rb
CHANGED