app_archetype 1.5.0 → 1.5.1

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: be0d0a9624d6408fce0b1b397a87dcdb1498fcce7f087106bcf89bf170dcd501
4
- data.tar.gz: 01220c7659a2d799f79ab847a69751e1e928e41f0c280998cbfe51436c53bc85
3
+ metadata.gz: 5349a7a225f734e2fb9a776dc35901784087f64f408cad6420e9f0e91697bb33
4
+ data.tar.gz: 8eb265ac52da61004ebc7a212520fefb3139720230cd5824a7dc690f833c5aad
5
5
  SHA512:
6
- metadata.gz: 50252b085dea58b00217c4a9e8d553564d0bc7bfddd12f8061344b91f75fb62a83388a191a4eff278e41de39c895133794d59cc6ba9d8f7f1adb46b165c9f1fc
7
- data.tar.gz: a67a216ec48665fcbf23a24e3a882ef2219b4cb170f50842cd976b88bbfabdb582980532a2be614e483238752d83111c8c88e4b4070a7433957069c8e500f6ef
6
+ metadata.gz: 78a4e55c5dff28403204480a49870a85914436a63187cbb167bbccb9023d87b317101a107a1faf39fbbd3479f7d54f6d6cd074341169f5006f79b62630dd24ee
7
+ data.tar.gz: 2fdfd6aaca47c4ddb6e7e45ebc3708dda871e60c927b4b61a30f79afe4b0f008aa1ed6e016a54ea42f028943b28b655f47e17675c7fa6f58efabc5ea3eee59f4
data/.rubocop.yml CHANGED
@@ -16,9 +16,21 @@
16
16
 
17
17
  Metrics/MethodLength:
18
18
  Max: 20
19
+ Exclude:
20
+ - 'lib/app_archetype/renderer.rb'
19
21
 
20
22
  Metrics/AbcSize:
21
23
  Max: 20
24
+ Exclude:
25
+ - 'lib/app_archetype/renderer.rb'
26
+
27
+ Metrics/CyclomaticComplexity:
28
+ Exclude:
29
+ - 'lib/app_archetype/renderer.rb'
30
+
31
+ Metrics/PerceivedComplexity:
32
+ Exclude:
33
+ - 'lib/app_archetype/renderer.rb'
22
34
 
23
35
  Lint/AssignmentInCondition:
24
36
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_archetype (1.5.0)
4
+ app_archetype (1.5.1)
5
5
  cli-format
6
6
  hashie
7
7
  highline
@@ -19,7 +19,7 @@ PATH
19
19
  GEM
20
20
  remote: https://rubygems.org/
21
21
  specs:
22
- activesupport (6.1.6)
22
+ activesupport (6.1.7.6)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 1.6, < 2)
25
25
  minitest (>= 5.1)
@@ -40,7 +40,7 @@ GEM
40
40
  coderay (1.1.3)
41
41
  coercible (1.0.0)
42
42
  descendants_tracker (~> 0.0.1)
43
- concurrent-ruby (1.1.10)
43
+ concurrent-ruby (1.2.2)
44
44
  descendants_tracker (0.0.4)
45
45
  thread_safe (~> 0.3, >= 0.3.1)
46
46
  diff-lcs (1.5.0)
@@ -57,22 +57,22 @@ GEM
57
57
  ruby_parser (~> 3.1, > 3.1.0)
58
58
  sexp_processor (~> 4.8)
59
59
  hashie (5.0.0)
60
- highline (2.0.3)
61
- i18n (1.10.0)
60
+ highline (2.1.0)
61
+ i18n (1.14.1)
62
62
  concurrent-ruby (~> 1.0)
63
63
  ice_nine (0.11.2)
64
- json (2.6.2)
65
- json-schema (3.0.0)
64
+ json (2.6.3)
65
+ json-schema (4.1.1)
66
66
  addressable (>= 2.8)
67
- jsonnet (0.4.0)
67
+ jsonnet (0.5.3)
68
68
  mini_portile2 (>= 2.2.0)
69
69
  kwalify (0.7.2)
70
70
  launchy (2.5.0)
71
71
  addressable (~> 2.7)
72
- logger (1.5.1)
72
+ logger (1.5.3)
73
73
  method_source (1.0.0)
74
- mini_portile2 (2.8.0)
75
- minitest (5.16.1)
74
+ mini_portile2 (2.8.4)
75
+ minitest (5.20.0)
76
76
  os (1.1.4)
77
77
  ostruct (0.5.5)
78
78
  parallel (1.21.0)
@@ -167,7 +167,7 @@ GEM
167
167
  strings (~> 0.2.0)
168
168
  tty-screen (~> 0.8)
169
169
  tty-which (0.4.2)
170
- tzinfo (2.0.4)
170
+ tzinfo (2.0.6)
171
171
  concurrent-ruby (~> 1.0)
172
172
  unicode-display_width (2.1.0)
173
173
  unicode_utils (1.4.0)
@@ -180,7 +180,7 @@ GEM
180
180
  wisper (2.0.1)
181
181
  yard (0.9.27)
182
182
  webrick (~> 1.7.0)
183
- zeitwerk (2.6.0)
183
+ zeitwerk (2.6.11)
184
184
 
185
185
  PLATFORMS
186
186
  ruby
@@ -44,6 +44,8 @@ module AppArchetype
44
44
  render_erb_file(file)
45
45
  elsif file.source_hbs?
46
46
  render_hbs_file(file)
47
+ elsif file.source_template?
48
+ render_template_file(file)
47
49
  elsif file.source_file?
48
50
  copy_file(file)
49
51
  end
@@ -100,7 +102,27 @@ module AppArchetype
100
102
  end
101
103
 
102
104
  ##
103
- # Copies source file to planned path only ovewriting if permitted by the
105
+ # Copies source file only overwriting if permitted by the
106
+ # renderer.
107
+ #
108
+ # The output file name removes the `.template` suffix. This
109
+ # is for circumstances where the template includes a hbs or erb
110
+ # file that we want to render untouched.
111
+ #
112
+ # @param [AppArchetype::OutputFile] file
113
+ #
114
+ def render_template_file(file)
115
+ raise 'cannot overwrite file' if file.exist? && !@overwrite
116
+
117
+ path = file.path.gsub('.template', '')
118
+
119
+ print_message("RENDER template ->: #{path}")
120
+
121
+ FileUtils.cp(file.source_file_path, path)
122
+ end
123
+
124
+ ##
125
+ # Copies source file to planned path only overwriting if permitted by the
104
126
  # renderer.
105
127
  #
106
128
  # @param [AppArchetype::Template::OutputFile] file
@@ -149,6 +149,18 @@ module AppArchetype
149
149
  File.extname(@source_file_path) == '.hbs'
150
150
  end
151
151
 
152
+ ##
153
+ # Evaluates whether the source file is a template.
154
+ #
155
+ # This is for cases where one wants to render a hbs or
156
+ # erb file without processing as a template file.
157
+ #
158
+ # @return [Boolean]
159
+ #
160
+ def source_template?
161
+ File.extname(@source_file_path) == '.template'
162
+ end
163
+
152
164
  ##
153
165
  # Evaluates whether the source file is a file as opposed to
154
166
  # being a directory.
@@ -2,5 +2,5 @@ module AppArchetype
2
2
  ##
3
3
  # AppArchetype version
4
4
  #
5
- VERSION = '1.5.0'.freeze
5
+ VERSION = '1.5.1'.freeze
6
6
  end
@@ -47,6 +47,13 @@ RSpec.describe AppArchetype::Renderer do
47
47
  )
48
48
  end
49
49
 
50
+ let(:template) do
51
+ AppArchetype::Template::OutputFile.new(
52
+ 'path/to/template.hbs.template',
53
+ 'path/to/destination/template'
54
+ )
55
+ end
56
+
50
57
  let(:directory) do
51
58
  AppArchetype::Template::OutputFile.new(
52
59
  'path/to/source/dir',
@@ -60,6 +67,7 @@ RSpec.describe AppArchetype::Renderer do
60
67
  allow(subject).to receive(:write_dir)
61
68
  allow(subject).to receive(:render_erb_file)
62
69
  allow(subject).to receive(:render_hbs_file)
70
+ allow(subject).to receive(:render_template_file)
63
71
  allow(subject).to receive(:copy_file)
64
72
 
65
73
  allow(File).to receive(:new).and_return(file_double)
@@ -67,11 +75,12 @@ RSpec.describe AppArchetype::Renderer do
67
75
  allow(file).to receive(:source_file?).and_return(true)
68
76
  allow(erb_template).to receive(:source_erb?).and_return(true)
69
77
  allow(hbs_template).to receive(:source_hbs?).and_return(true)
78
+ allow(template).to receive(:source_template?).and_return(true)
70
79
  allow(directory).to receive(:source_directory?).and_return(true)
71
80
 
72
81
  plan.instance_variable_set(
73
82
  :@files,
74
- [file, erb_template, hbs_template, directory]
83
+ [file, erb_template, hbs_template, template, directory]
75
84
  )
76
85
 
77
86
  subject.render
@@ -93,6 +102,10 @@ RSpec.describe AppArchetype::Renderer do
93
102
  expect(subject).to have_received(:render_hbs_file).with(hbs_template)
94
103
  end
95
104
 
105
+ it 'renders template' do
106
+ expect(subject).to have_received(:render_template_file).with(template)
107
+ end
108
+
96
109
  it 'copies file' do
97
110
  expect(subject).to have_received(:copy_file).with(file)
98
111
  end
@@ -247,6 +260,48 @@ RSpec.describe AppArchetype::Renderer do
247
260
  end
248
261
  end
249
262
 
263
+ describe '#render_template_file' do
264
+ let(:source_path) { 'path/to/template/file.hbs.template' }
265
+ let(:dest_path) { 'path/to/destination/file' }
266
+
267
+ let(:file) do
268
+ AppArchetype::Template::OutputFile.new(source_path, dest_path)
269
+ end
270
+
271
+ let(:exists) { false }
272
+
273
+ before do
274
+ allow(FileUtils).to receive(:cp)
275
+ allow(file).to receive(:exist?).and_return(exists)
276
+ end
277
+
278
+ it 'copies file' do
279
+ subject.render_template_file(file)
280
+ expect(FileUtils).to have_received(:cp).with(source_path, dest_path)
281
+ end
282
+
283
+ context 'when file already exists and overwrite not allowed' do
284
+ let(:exists) { true }
285
+
286
+ it 'raises error' do
287
+ expect do
288
+ subject.render_template_file(file)
289
+ end.to raise_error('cannot overwrite file')
290
+ end
291
+ end
292
+
293
+ context 'when file already exists and overwrite is allowed' do
294
+ let(:exists) { true }
295
+ let(:overwrite) { true }
296
+
297
+ it 'raises error' do
298
+ expect do
299
+ subject.render_template_file(file)
300
+ end.not_to raise_error
301
+ end
302
+ end
303
+ end
304
+
250
305
  describe '#copy_file' do
251
306
  let(:source_path) { 'path/to/template/file' }
252
307
  let(:dest_path) { 'path/to/destination/file' }
@@ -167,6 +167,31 @@ RSpec.describe AppArchetype::Template::OutputFile do
167
167
  end
168
168
  end
169
169
 
170
+ describe '#source_template?' do
171
+ let(:ext) { '.template' }
172
+
173
+ before do
174
+ allow(File).to receive(:extname).and_return(ext)
175
+ @result = subject.source_template?
176
+ end
177
+
178
+ it 'delegates source file template check to File' do
179
+ expect(File).to have_received(:extname).with(source_file)
180
+ end
181
+
182
+ it 'returns true if file is template' do
183
+ expect(@result).to be true
184
+ end
185
+
186
+ context 'when not template' do
187
+ let(:ext) { 'doc' }
188
+
189
+ it 'returns false' do
190
+ expect(@result).to be false
191
+ end
192
+ end
193
+ end
194
+
170
195
  describe '#source_file?' do
171
196
  before do
172
197
  allow(File).to receive(:file?)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_archetype
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bigger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-27 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-format