materielize 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/materielize/version.rb +1 -1
- data/lib/materielize.rb +11 -6
- data/lib/tasks/materiel.rake +21 -1
- data/spec/models/config_files_spec.rb +12 -9
- metadata +2 -2
data/lib/materielize/version.rb
CHANGED
data/lib/materielize.rb
CHANGED
@@ -45,13 +45,17 @@ module Materielize
|
|
45
45
|
FileUtils.rm_rf(root_path)
|
46
46
|
end
|
47
47
|
|
48
|
-
def init_cfg_files
|
49
|
-
@overwrite_all = false # initialize
|
48
|
+
def init_cfg_files(options = {})
|
49
|
+
@overwrite_all = {force_all: false}.merge(options)[:force_all] # initialize if not indicated so as to not inadvertently cause disaster on a second call or somesuch.
|
50
50
|
@project_root = Dir.getwd
|
51
51
|
@root = File.expand_path(default_config_dir, root_dir)
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
begin
|
54
|
+
copy([root_dir, default_config_dir]) do |item|
|
55
|
+
yield(item)
|
56
|
+
end
|
57
|
+
rescue Interrupt => e
|
58
|
+
puts e
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
@@ -132,8 +136,9 @@ module Materielize
|
|
132
136
|
|
133
137
|
# Check for a user cancellation before anything is done.
|
134
138
|
if %w[c C].include?(options[:confirmation])
|
135
|
-
|
136
|
-
|
139
|
+
message = "User cancelled operation."
|
140
|
+
report_back(block, message: message)
|
141
|
+
raise Interrupt.new(message)
|
137
142
|
end
|
138
143
|
end
|
139
144
|
|
data/lib/tasks/materiel.rake
CHANGED
@@ -27,9 +27,11 @@ namespace :materiel do
|
|
27
27
|
|
28
28
|
desc "Copy default config files into place."
|
29
29
|
task :init_config_files do
|
30
|
+
force = parse_args(ARGV)
|
31
|
+
|
30
32
|
setup = Materielize::ConfigSetup.new
|
31
33
|
|
32
|
-
setup.init_cfg_files do |item|
|
34
|
+
setup.init_cfg_files(force_all: force) do |item|
|
33
35
|
if item[:needs_confirmation]
|
34
36
|
item[:confirmation] = ask(item[:message])
|
35
37
|
puts
|
@@ -40,4 +42,22 @@ namespace :materiel do
|
|
40
42
|
|
41
43
|
puts "Done."
|
42
44
|
end
|
45
|
+
|
46
|
+
def parse_args(args)
|
47
|
+
if args.count > 2
|
48
|
+
puts "'force' is the only option"
|
49
|
+
puts "EX: rake materiel:init_config_files force"
|
50
|
+
raise ArgumentError
|
51
|
+
end
|
52
|
+
|
53
|
+
# No args given
|
54
|
+
return false if args.count == 1
|
55
|
+
|
56
|
+
# Swallow the arg so that it's not considered a real rake task by rake
|
57
|
+
option = args[1]
|
58
|
+
task option.to_sym do ; end
|
59
|
+
|
60
|
+
# Return true if force given as an arg.
|
61
|
+
return args[1].downcase == "force"
|
62
|
+
end
|
43
63
|
end
|
@@ -198,17 +198,17 @@ describe Materielize::ConfigSetup do
|
|
198
198
|
file1_path = "materiel/default_config_files/#{sub1}/config_file.txt"
|
199
199
|
|
200
200
|
# Place spoof file in its 'production' location to be found by process
|
201
|
-
FileUtils.cp(existing_file_name, "./
|
202
|
-
@files_to_nuke << "
|
201
|
+
FileUtils.cp(existing_file_name, "./config_file.txt")
|
202
|
+
@files_to_nuke << "config_file.txt"
|
203
203
|
|
204
204
|
|
205
205
|
# Creating file path of default_cfg_file here for organization
|
206
206
|
Dir.mkdir("config")
|
207
207
|
@paths_to_nuke << "config"
|
208
|
-
file2_path = "materiel/default_config_files/
|
208
|
+
file2_path = "materiel/default_config_files/config_file.txt"
|
209
209
|
|
210
210
|
# Place spoof file in its 'production' location to be found by process
|
211
|
-
FileUtils.cp(existing_file_name, "config/
|
211
|
+
FileUtils.cp(existing_file_name, "config/config_file.txt")
|
212
212
|
|
213
213
|
create_subdirectory(sub1)
|
214
214
|
|
@@ -217,17 +217,20 @@ describe Materielize::ConfigSetup do
|
|
217
217
|
FileUtils.cp(src_file_name, file1_path)
|
218
218
|
FileUtils.cp(src_file_name, file2_path)
|
219
219
|
|
220
|
+
prompts = 0
|
220
221
|
@setup.init_cfg_files do |item|
|
221
222
|
if item[:needs_confirmation] == true
|
222
223
|
# Deny the process's request to write over the file.
|
223
224
|
item[:confirmation] = "n"
|
225
|
+
prompts += 1
|
224
226
|
end
|
225
227
|
end
|
228
|
+
prompts.should eq 2
|
226
229
|
|
227
|
-
FileUtils.identical?(existing_file_name, "
|
228
|
-
FileUtils.identical?(existing_file_name, "config/
|
229
|
-
FileUtils.identical?(src_file_name, "
|
230
|
-
FileUtils.identical?(src_file_name, "config/
|
230
|
+
FileUtils.identical?(existing_file_name, "config_file.txt").should be true
|
231
|
+
FileUtils.identical?(existing_file_name, "config/config_file.txt").should be true
|
232
|
+
FileUtils.identical?(src_file_name, "config_file.txt").should be false
|
233
|
+
FileUtils.identical?(src_file_name, "config/config_file.txt").should be false
|
231
234
|
end
|
232
235
|
|
233
236
|
it "overwrites existing files if the user indicates yes" do
|
@@ -356,10 +359,10 @@ describe Materielize::ConfigSetup do
|
|
356
359
|
|
357
360
|
i = 0
|
358
361
|
@setup.init_cfg_files do |item|
|
359
|
-
i += 1
|
360
362
|
if item[:needs_confirmation] == true
|
361
363
|
# Cancel the whole deal.
|
362
364
|
item[:confirmation] = "c"
|
365
|
+
i += 1
|
363
366
|
end
|
364
367
|
end
|
365
368
|
i.should eq 1 # There should have been one prompt
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: materielize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|