foobara-files-generator 0.2.3 → 0.2.4

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: 9b5e0899d58f9d037fea95e1489d31efca9365b3e0d9960055c5d643411ed1dc
4
- data.tar.gz: 735bf4d1d789194d1df0ac45cb57495838404883ffcb86759f44e802aca7d50c
3
+ metadata.gz: c899e8d56d1907a4208972cefe48daf7de688932db3a61be2bbd60d0cb93cadc
4
+ data.tar.gz: 7fea1d8fb7d57a43a6b7922496c081170735b29ed55763b43b501680847e0779
5
5
  SHA512:
6
- metadata.gz: 5acbfd8b48fc88dbd2d1908e9eb3c4c08dad811a804a21b48e2a23d09d78c0280b4b5042bda21640788d54a39625dff14d80536709fd8da2eafd0e6e353f0049
7
- data.tar.gz: 848995fcf8abb6af650c59b9299708ebbf3c68b706ee9f5d9b0a9e0da66eb4d59861137e98b2069279b8fea1ba39db4d30413db0795175b4ffa34001be6b5fa1
6
+ metadata.gz: ac403ec29ecfce532ebd32140a12ec42e00911ee57c6a5cb3766b071934c5f6b9f16bc828b23e9ae499157e327aad403afa9cebe22a5b91e89fec224468788e3
7
+ data.tar.gz: e6c520133746e6e7768f6a0366c0ecca00584dd9e1a8e3617d8073a0859cddc9c46addfcadf4ecd7b53d7a15afacff4058690332fb00be700128fc1b1d0a4aba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.2.4] - 2026-10-06
2
+
3
+ - Rotate generated files json with a deprecated name
4
+ to non-deprecated name if it has a deprecated name
5
+ - If file contents are empty after deleting interpolated content
6
+ then delete the file instead of writing it
7
+ - Add an InterpolatingGenerator mixin
8
+
1
9
  ## [0.2.3] - 2026-10-05
2
10
 
3
11
  - Make sure version.rb is loaded where it might be used
@@ -0,0 +1,57 @@
1
+ module Foobara
2
+ module InterpolatingGenerator
3
+ def generate(_elements_to_generate)
4
+ start_marker = self.start_marker
5
+ end_marker = self.end_marker
6
+
7
+ content = "#{start_marker}#{new_content}#{end_marker}"
8
+
9
+ if File.exist?(template_path)
10
+ match = insert_at&.match(target_contents)
11
+
12
+ content = if match
13
+ if match.captures.empty?
14
+ pre = match[0]
15
+ post = ""
16
+ else
17
+ pre, *post = match.captures
18
+ post = post.join
19
+ end
20
+
21
+ "#{match.pre_match}#{pre}#{content}#{post}#{match.post_match}"
22
+ else
23
+ "#{target_contents}#{content}"
24
+ end
25
+ else
26
+ match = /\A\n+/.match(content)
27
+
28
+ # simplecov:disable
29
+ if match
30
+ # simplecov:enable
31
+ newline_count = match[0].size
32
+ start_marker = start_marker[newline_count..]
33
+ content = match.post_match
34
+ end
35
+
36
+ match = /\n+\z/.match(content)
37
+
38
+ # simplecov:disable
39
+ if match
40
+ # simplecov:enable
41
+ newline_count = match[0].size
42
+ end_marker = end_marker[...-newline_count]
43
+ content = match.pre_match
44
+ end
45
+
46
+ content = "#{content}\n"
47
+ end
48
+
49
+ { content:, start_marker:, end_marker: }
50
+ end
51
+
52
+ def new_content = raise NotImplementedError
53
+ def insert_at = nil
54
+ def start_marker = raise NotImplementedError
55
+ def end_marker = raise NotImplementedError
56
+ end
57
+ end
@@ -79,7 +79,13 @@ module Foobara
79
79
  contents
80
80
  end
81
81
 
82
+ def old_generated_files_path(key = self.class.generator_key)
83
+ "#{output_directory}/#{generated_files_json_filename(key)}"
84
+ end
85
+
82
86
  def delete_old_files_if_needed
87
+ rotate_old_generated_files_json_if_needed
88
+
83
89
  generated_files_info = old_generated_files_json_contents
84
90
 
85
91
  return unless generated_files_info
@@ -97,6 +103,26 @@ module Foobara
97
103
  end.each(&:join)
98
104
  end
99
105
 
106
+ def rotate_old_generated_files_json_if_needed
107
+ keys = self.class.generator_key
108
+
109
+ return unless keys.is_a?(::Array)
110
+
111
+ key, *deprecated_keys = keys
112
+
113
+ non_deprecated_path = old_generated_files_path(key)
114
+ return if File.exist?(non_deprecated_path)
115
+
116
+ deprecated_keys.each do |key|
117
+ path = old_generated_files_path(key)
118
+
119
+ if File.exist?(path)
120
+ FileUtils.mv(path, non_deprecated_path)
121
+ break
122
+ end
123
+ end
124
+ end
125
+
100
126
  def write_all_files_to_disk
101
127
  paths_to_source_code.map do |path, generated_file|
102
128
  Thread.new do
@@ -128,9 +154,7 @@ module Foobara
128
154
  end
129
155
  end
130
156
 
131
- def generated_files_json_filename
132
- key = self.class.generator_key
133
-
157
+ def generated_files_json_filename(key = self.class.generator_key)
134
158
  if key
135
159
  key = key.first if key.is_a?(::Array)
136
160
 
@@ -225,7 +249,7 @@ module Foobara
225
249
  return unless end_index
226
250
  # simplecov:enable
227
251
 
228
- end_index += start_index + start_marker.size + 1
252
+ end_index += start_index + start_marker.size
229
253
  end_index += end_marker.size
230
254
 
231
255
  keep_first = contents[0...start_index]
@@ -233,7 +257,11 @@ module Foobara
233
257
 
234
258
  contents = keep_first + keep_last
235
259
 
236
- File.write(file_path, contents)
260
+ if contents.strip.empty?
261
+ FileUtils.rm_f(file_path)
262
+ else
263
+ File.write(file_path, contents)
264
+ end
237
265
  end
238
266
  end
239
267
  end
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foobara
2
2
  class FilesGenerator
3
- VERSION = "0.2.3".freeze
3
+ VERSION = "0.2.4".freeze
4
4
  MINIMUM_RUBY_VERSION = [">= 3.4.0", "< 4.1"].freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-files-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -45,6 +45,7 @@ files:
45
45
  - src/files_generator.rb
46
46
  - src/files_generator/bundler_actions.rb
47
47
  - src/generate.rb
48
+ - src/interpolating_generator.rb
48
49
  - src/symlink.rb
49
50
  - src/types/generate_result.rb
50
51
  - src/types/generated_file.rb