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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38343450afa850225b6db642c0a34b5cbe506bc2933f0fe163aa565c35b6cc81
4
- data.tar.gz: 129c55a6913e11e3b60ee2164707bd23740fe6dc7c85ec9433d9e3ed88556af8
3
+ metadata.gz: 7cc77a4ee2eb9f30b13efc22f5eaedff1b564f9831c3b7f4d9430b80185ffb83
4
+ data.tar.gz: fbe4135c3c9c08d46c1ee39b1b3de0c28fd2be547243d2137e49517997052d96
5
5
  SHA512:
6
- metadata.gz: 4e790a691d39c301a013792b1a4f96e91730928071cfcdcf09519643404113dbaf6b0a6b34179ad2620f757b9a9ddce42f6068303bcfb760cc90eb69c66df326
7
- data.tar.gz: 55566a7f6f51164991767429473e3de9306c03bb60f66bf715510916c5e4fc1c61d94b5f559b033788874f4ddf25e3acd3feb216f6dd213b48691dab0d6876b7
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.23] - 2024-07-xx
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.22] - 2024-07-16
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 = @enviro.config if @enviro && init.empty?
13
+ init = @enviro.config if @enviro && init.empty?
14
+
15
15
  @timestamp_pattern = init.files.timestamp_pattern || DEFAULT_TIMESTAMP_PATTERN
16
- self.dir_path = init.working_directory || Dir.pwd
16
+ self.dir_path = init.working_directory || Dir.pwd
17
17
  end
18
18
 
19
19
  def dir_path=(value)
20
- begin
21
- @dir = Eco::Data::Files::Directory.new(value)
22
- @dir_path = @dir.create
23
- rescue Exception => e
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
- if !file
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
- content = file_content(filename)
53
- begin
54
- parsed = content && JSON.parse(content)
55
- rescue JSON::ParserError => e
56
- pp "Parsing error on file #{filename}"
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
- return parsed
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 save(content, filename, modifier = :no_stamp, mode: :string)
67
- file = dir.file(filename)
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
- FileManager.create_directory(FileManager.file_fullpath(file))
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
- File.open(file, mode) { |fd| fd << content }
75
- return file
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 save_json(data, filename, modifier = :no_stamp)
79
- return save(data.to_json, filename, modifier)
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
- File.open(file, mode) { |fd| fd << content + "\n" } # '\n' won't add line
89
- return file
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
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = '2.7.21'.freeze
2
+ VERSION = '2.7.22'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.21
4
+ version: 2.7.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura