foobara-files-generator 0.2.2 → 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: df95bccb20d285f6a4d66ecf369a5f17dfcef70919ef6f01a8c5cefe292c1ff6
4
- data.tar.gz: 478f05f8263aca0903ac8c2c32d662eef5a3e2e67ef5ab5b238e7eb530ce1f95
3
+ metadata.gz: c899e8d56d1907a4208972cefe48daf7de688932db3a61be2bbd60d0cb93cadc
4
+ data.tar.gz: 7fea1d8fb7d57a43a6b7922496c081170735b29ed55763b43b501680847e0779
5
5
  SHA512:
6
- metadata.gz: d16ded0c98534d3630a16728b81695bbffc474a27b64013b1a92d45e1e76eba308b606b6554d14657da16b9174e02a15f82d622d9d4fc633bb46cc1100f56344
7
- data.tar.gz: 76ee763276af53d21ac6888a85ada467257c54aaddd26b0bd0e2d7231ae5a828139ff80d5239dae25a3360690b5b41f3cb5f7918a45a242471f436cccc9d2878
6
+ metadata.gz: ac403ec29ecfce532ebd32140a12ec42e00911ee57c6a5cb3766b071934c5f6b9f16bc828b23e9ae499157e327aad403afa9cebe22a5b91e89fec224468788e3
7
+ data.tar.gz: e6c520133746e6e7768f6a0366c0ecca00584dd9e1a8e3617d8073a0859cddc9c46addfcadf4ecd7b53d7a15afacff4058690332fb00be700128fc1b1d0a4aba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
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
+
9
+ ## [0.2.3] - 2026-10-05
10
+
11
+ - Make sure version.rb is loaded where it might be used
12
+
1
13
  ## [0.2.2] - 2026-10-05
2
14
 
3
15
  - Include version.rb in gem
@@ -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
@@ -1,5 +1,6 @@
1
1
  require "fileutils"
2
2
  require "open3"
3
+ require_relative "../version"
3
4
 
4
5
  module Foobara
5
6
  module Generators
@@ -78,7 +79,13 @@ module Foobara
78
79
  contents
79
80
  end
80
81
 
82
+ def old_generated_files_path(key = self.class.generator_key)
83
+ "#{output_directory}/#{generated_files_json_filename(key)}"
84
+ end
85
+
81
86
  def delete_old_files_if_needed
87
+ rotate_old_generated_files_json_if_needed
88
+
82
89
  generated_files_info = old_generated_files_json_contents
83
90
 
84
91
  return unless generated_files_info
@@ -96,6 +103,26 @@ module Foobara
96
103
  end.each(&:join)
97
104
  end
98
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
+
99
126
  def write_all_files_to_disk
100
127
  paths_to_source_code.map do |path, generated_file|
101
128
  Thread.new do
@@ -127,9 +154,7 @@ module Foobara
127
154
  end
128
155
  end
129
156
 
130
- def generated_files_json_filename
131
- key = self.class.generator_key
132
-
157
+ def generated_files_json_filename(key = self.class.generator_key)
133
158
  if key
134
159
  key = key.first if key.is_a?(::Array)
135
160
 
@@ -224,7 +249,7 @@ module Foobara
224
249
  return unless end_index
225
250
  # simplecov:enable
226
251
 
227
- end_index += start_index + start_marker.size + 1
252
+ end_index += start_index + start_marker.size
228
253
  end_index += end_marker.size
229
254
 
230
255
  keep_first = contents[0...start_index]
@@ -232,7 +257,11 @@ module Foobara
232
257
 
233
258
  contents = keep_first + keep_last
234
259
 
235
- 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
236
265
  end
237
266
  end
238
267
  end
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foobara
2
2
  class FilesGenerator
3
- VERSION = "0.2.2".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.2
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