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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38343450afa850225b6db642c0a34b5cbe506bc2933f0fe163aa565c35b6cc81
4
- data.tar.gz: 129c55a6913e11e3b60ee2164707bd23740fe6dc7c85ec9433d9e3ed88556af8
3
+ metadata.gz: 1d522c29136b4722235f8dbf8349d7328ba7ebe90f77d5fecf15a03a049cc8fe
4
+ data.tar.gz: b2529b04d22fcc9f013366c07a5bb7905c8d6154af97c4d235fafc1f0bf6452b
5
5
  SHA512:
6
- metadata.gz: 4e790a691d39c301a013792b1a4f96e91730928071cfcdcf09519643404113dbaf6b0a6b34179ad2620f757b9a9ddce42f6068303bcfb760cc90eb69c66df326
7
- data.tar.gz: 55566a7f6f51164991767429473e3de9306c03bb60f66bf715510916c5e4fc1c61d94b5f559b033788874f4ddf25e3acd3feb216f6dd213b48691dab0d6876b7
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.23] - 2024-07-xx
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.22] - 2024-07-16
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
- - Ability to skip GraphQL schema fetch (`GRAPHQL_FETCH_SCHEMA`)
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 = @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 => 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
- 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
+ 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
- File.basename(fullname, File.extname(fullname))
62
- end
63
+ return nil unless fullname
63
64
 
64
- def file_path(fullname)
65
- File.dirname(fullname)
65
+ File.basename(fullname, File.extname(fullname))
66
66
  end
67
67
 
68
68
  def file_fullpath(fullname)
69
- file_path(File.expand_path(fullname))
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
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = '2.7.21'.freeze
2
+ VERSION = '2.7.23'.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.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura