materielize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2-p320
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in materielize.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ray Parker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Materielize
2
+
3
+ This is to assist in the always-messy proposition of configuration files and the like that need to be part of your project, but you don't want production credentials and such being posted in your repo. Also, as settings are added to project for new features (i.e., configuration settings in YAML files), team members will want to get the updated default settings for their development environment.
4
+
5
+ Materielize is born out of the way that I prefer to deal with this. I invariably have a 'materiel' directory that contains various things that are needed in the project, but not necessarily part of the code base. Also, I have a directory tree the mirrors the project itself with all of the default configuration files. When setting up the project fresh, materielize gives you Thor tasks to create the basic structure (install) and then copy config files over to your project from the default (init_config_files).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'materielize'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install materielize
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,163 @@
1
+ require "materielize/version"
2
+ require "materielize/railtie" if defined?(Rails)
3
+
4
+ module Materielize
5
+ class ConfigSetup
6
+ attr_reader :root_dir, :default_config_dir
7
+
8
+ def initialize
9
+ @root_dir = "materiel"
10
+ @default_config_dir = "default_config_files"
11
+ @overwrite_all = false
12
+ end
13
+
14
+ def materiel_exists?
15
+ Dir.exists?(root_dir)
16
+ end
17
+
18
+ def default_config_dir_exists?
19
+ Dir.exists?(sub_path(default_config_dir))
20
+ end
21
+
22
+ # Basic setup of materiel. Create materiel directory, default config subdirectory, throw around some READMEs, etc.
23
+ def install
24
+ root_path = File.expand_path(root_dir)
25
+ if !materiel_exists?
26
+ yield({message: "Creating directory '#{root_path}'."}) if block_given?
27
+ Dir.mkdir(root_path)
28
+ else
29
+ yield({message: "Directory '#{root_path}' already exists, no need to create."}) if block_given?
30
+ end
31
+
32
+ default_config_path = File.expand_path(default_config_dir, root_dir)
33
+
34
+ if !default_config_dir_exists?
35
+ yield({message: "Creating directory '#{default_config_path}'."}) if block_given?
36
+ Dir.mkdir(default_config_path)
37
+ else
38
+ yield({message: "Directory '#{default_config_path}' already exists, no need to create."}) if block_given?
39
+ end
40
+ end
41
+
42
+ def uninstall
43
+ root_path = File.expand_path(root_dir)
44
+ yield({message: "Uninstalling: Removing #{root_path}"}) if block_given?
45
+ FileUtils.rm_rf(root_path)
46
+ end
47
+
48
+ def init_cfg_files
49
+ @overwrite_all = false # initialize this do as to not inadvertently cause disaster on a second call or somesuch.
50
+ @project_root = Dir.getwd
51
+ @root = File.expand_path(default_config_dir, root_dir)
52
+
53
+ copy([root_dir, default_config_dir]) do |item|
54
+ yield(item)
55
+ end
56
+ end
57
+
58
+ # Valid single-character responses from the user
59
+ def accepted_user_responses
60
+ %w[a A n N c C] + [true, false]
61
+ end
62
+
63
+ # Confirm that the user response is valid. Accepts either a string (char) response or the
64
+ # the whole response/messaging hash. Booleans also accepted.
65
+ def valid_user_response?(response)
66
+ if response.is_a?(String) || response.is_a?(TrueClass)|| response.is_a?(FalseClass)
67
+ accepted_user_responses.include?(response)
68
+ elsif response.is_a?(Hash)
69
+ accepted_user_responses.include?(response[:confirmation])
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ # Create path relative to 'materiel'
76
+ def sub_path(name)
77
+ File.expand_path(name, root_dir)
78
+ end
79
+
80
+ # This only handles a yes, no or all type of response. If a (c)ancel response
81
+ # is to be caught, do it before you check with this.
82
+ def user_confirmed?(response_options)
83
+ # overwrite all sticks
84
+ return @overwrite_all if @overwrite_all
85
+
86
+ # no response is a false response
87
+ return false if response_options[:confirmation].nil?
88
+
89
+ # make response lower case for simplicity
90
+ response = response_options[:confirmation].downcase
91
+
92
+ # Set overwrite all and return if indicated
93
+ @overwrite_all = true if response == "a"
94
+ return @overwrite_all if @overwrite_all
95
+
96
+
97
+ return false if response == "n"
98
+ true if response == "y"
99
+ end
100
+
101
+ def copy(path_parts, &block)
102
+ current_path = File.expand_path(File.join(*path_parts))
103
+
104
+ for entry in Dir.entries(File.expand_path(current_path, ".")) do
105
+ next if entry == "." || entry == ".."
106
+
107
+ # The original, be it a directory or a file
108
+ src = File.expand_path(entry, current_path)
109
+
110
+ # The thing that might need to be created, copied, etc.
111
+ target = File.join(@project_root, *path_parts.reject{|part| [root_dir, default_config_dir].include?(part)}, entry)
112
+
113
+ if File.directory?(src)
114
+ # Figure path of an unknown depth of directories and subdirectories, slice off the materiel directory
115
+ # and create the currently found directory under its matching sibling under the project root
116
+ if !Dir.exist?(target)
117
+ report_back(block, :message => "Creating directory '#{target}'.")
118
+ Dir.mkdir(target)
119
+ end
120
+
121
+ # Inter-dimensional travel time...
122
+ copy(path_parts + [entry], &block)
123
+ else
124
+ # It's a file
125
+ if File.exist?(target)
126
+ # Initialize, but value won't (shouldn't) be used
127
+ options = {}
128
+
129
+ # If a forced overwrite of all is indicated, this stuff gets in the way.
130
+ if !@overwrite_all
131
+ options = report_back(block, {message: "'#{target}' exists. Overwrite? (y)es, (n)o, (a)ll or (c)ancel: ", needs_confirmation: true, confirmation: false})
132
+
133
+ # Check for a user cancellation before anything is done.
134
+ if %w[c C].include?(options[:confirmation])
135
+ report_back(block, message: "Operation cancelled.")
136
+ return
137
+ end
138
+ end
139
+
140
+ # Replace the file if the user confirms or has chosen "all"
141
+ if @overwrite_all || user_confirmed?(options)
142
+ report_back(block, {message: "Replacing #{target} because a force/replace was indicated."})
143
+ FileUtils.rm(target)
144
+ FileUtils.cp(src, target)
145
+ else
146
+ report_back(block, {message: "Skipping #{target}"})
147
+ end
148
+ else
149
+ # File doesn't exist, so jsut write it.
150
+ report_back(block, message: "Creating #{target}.")
151
+ FileUtils.cp(src, target)
152
+ end
153
+ end
154
+ end
155
+ end
156
+
157
+ def report_back(block, options)
158
+ default_options = {needs_confirmation: false, confirmation: false}.merge(options)
159
+ block.call(default_options)
160
+ default_options
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,13 @@
1
+ require 'materielize'
2
+ require 'rails'
3
+
4
+ module Materielize
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :materielize
7
+
8
+ rake_tasks do
9
+ load "lib/tasks/materiel.rake"
10
+ #load "lib/tasks/materiel.thor"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Materielize
2
+ VERSION = "0.0.1"
3
+ end
data/lib/root.txt ADDED
@@ -0,0 +1 @@
1
+ This directory will reflect the root directory of your project. Things put here will be copied to your project's root directory. Subdirectories and their content will be copied as subdirectories of your project root, etc.
@@ -0,0 +1,43 @@
1
+ #noinspection RubyResolve
2
+ require "materielize"
3
+ require "highline/import"
4
+
5
+ namespace :materiel do
6
+ desc "install", "Set up the materielize directory if it doesn't already exist"
7
+ task :install do
8
+ setup = Materielize::ConfigSetup.new
9
+
10
+ setup.install do |item|
11
+ puts item[:message]
12
+ end
13
+
14
+ puts "Done."
15
+ end
16
+
17
+ desc "uninstall", "Remove the materiel directory"
18
+ task :uninstall do
19
+ setup = Materielize::ConfigSetup.new
20
+
21
+ setup.uninstall do |item|
22
+ puts item[:message]
23
+ end
24
+
25
+ puts "Done."
26
+ end
27
+
28
+ desc "init_config_files", "Copy default config files into place."
29
+ task :init_config_files do
30
+ setup = Materielize::ConfigSetup.new
31
+
32
+ setup.init_cfg_files do |item|
33
+ if item[:needs_confirmation]
34
+ item[:confirmation] = ask(item[:message])
35
+ puts
36
+ else
37
+ puts item[:message]
38
+ end
39
+ end
40
+
41
+ puts "Done."
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ #noinspection RubyResolve
2
+ require "materielize"
3
+ require "highline/import"
4
+
5
+ class Materiel < Thor
6
+ desc "install", "Set up the materielize directory if it doesn't already exist"
7
+ def install
8
+ setup = Materielize::ConfigSetup.new
9
+
10
+ setup.install do |item|
11
+ puts item[:message]
12
+ end
13
+
14
+ puts "Done."
15
+ end
16
+
17
+ desc "uninstall", "Remove the materiel directory"
18
+ def uninstall
19
+ setup = Materielize::ConfigSetup.new
20
+
21
+ setup.uninstall do |item|
22
+ puts item[:message]
23
+ end
24
+
25
+ puts "Done."
26
+ end
27
+
28
+ desc "init_config_files", "Copy default config files into place."
29
+ def init_config_files
30
+ setup = Materielize::ConfigSetup.new
31
+
32
+ setup.init_cfg_files do |item|
33
+ if item[:needs_confirmation]
34
+ item[:confirmation] = ask(item[:message])
35
+ puts
36
+ else
37
+ puts item[:message]
38
+ end
39
+ end
40
+
41
+ puts "Done."
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/materielize/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ray Parker"]
6
+ gem.email = ["RayParkerBassPlayer@gmail.com"]
7
+ gem.description = %q{A helper for default config files.}
8
+ gem.summary = %q{Helps with the stowage and installation of default config files -- helpful for dev and CI environments.}
9
+ gem.homepage = "http://github.com/RayParkerBassPlayer/materielize"
10
+
11
+ gem.add_development_dependency "rspec"
12
+ gem.add_development_dependency "rake"
13
+
14
+ gem.add_dependency "thor"
15
+ gem.add_dependency "highline"
16
+
17
+ gem.files = `git ls-files`.split($\)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.name = "materielize"
21
+ gem.require_paths = ["lib"]
22
+ gem.version = Materielize::VERSION
23
+ end
File without changes
@@ -0,0 +1 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,377 @@
1
+ #noinspection RubyResolve
2
+ require "spec_helper"
3
+
4
+ describe Materielize::ConfigSetup do
5
+ before(:all) do
6
+ @setup = Materielize::ConfigSetup.new
7
+
8
+ @materiel_dir = "materiel"
9
+ @default_config_files_dir = "default_config_files"
10
+ @default_config_files_path = "#@materiel_dir/#@default_config_files_dir"
11
+ end
12
+
13
+ before(:each) do
14
+ # Start each spec out in fresh territory
15
+ @setup.uninstall
16
+ end
17
+
18
+ after(:all) do
19
+ # just like a good neighbor...
20
+ @setup.uninstall
21
+ end
22
+
23
+ context "installation" do
24
+ it "creates basic directories if they don't exist" do
25
+ @setup.install
26
+
27
+ @setup.materiel_exists?.should be true
28
+ @setup.default_config_dir_exists?.should be true
29
+ end
30
+
31
+ it "handles installation if directories do exist" do
32
+ @setup.install
33
+
34
+ @setup.materiel_exists?.should be true
35
+ @setup.default_config_dir_exists?.should be true
36
+ end
37
+ end
38
+
39
+ context "micro-ish helpers" do
40
+ it "recognizes correctly if the materiel directory exists" do
41
+ @setup.install
42
+ @setup.materiel_exists?.should be true
43
+ end
44
+
45
+ it "recognizes correctly if the materiel directory does not exist" do
46
+ @setup.materiel_exists?.should be false
47
+ end
48
+ it "recognizes if the default config files directory doesn't exist" do
49
+ @setup.default_config_dir_exists?.should be false
50
+ end
51
+
52
+ it "recognizes if the default config files directory does exist" do
53
+ @setup.install
54
+ @setup.default_config_dir_exists?.should be true
55
+ end
56
+
57
+ it "recognizes good responses in the form of strings" do
58
+ for response in @setup.accepted_user_responses
59
+ @setup.valid_user_response?(response).should be true
60
+ end
61
+ end
62
+
63
+ it "recognizes good responses in the form of a response hash" do
64
+ for response in @setup.accepted_user_responses
65
+ @setup.valid_user_response?(confirmation: response).should be true
66
+ end
67
+ end
68
+
69
+ it "recognizes bad responses in the form of strings" do
70
+ @setup.valid_user_response?("H").should be false
71
+ end
72
+
73
+ it "recognizes bad responses in the form of a response hash" do
74
+ @setup.valid_user_response?(confirmation: "H").should be false
75
+ end
76
+ end
77
+
78
+ context "copying default tree" do
79
+ before(:each) do
80
+ @paths_to_nuke = []
81
+ @files_to_nuke = []
82
+ @setup.install
83
+ end
84
+
85
+ after(:each) do
86
+ for path in @paths_to_nuke do
87
+ FileUtils.rm_rf(path)
88
+ end
89
+
90
+ for file in @files_to_nuke
91
+ FileUtils.rm(file)
92
+ end
93
+ end
94
+
95
+ context "creating reflection of default config directory" do
96
+ it "handles creating directories that don't exist" do
97
+ dir_name = "sub1"
98
+ @paths_to_nuke << dir_name
99
+
100
+ create_subdirectory(dir_name)
101
+
102
+ @setup.init_cfg_files do |item|
103
+ puts item[:message]
104
+
105
+ if item[:needs_confirmation] == true
106
+ item[:confirmation] = true
107
+ end
108
+ end
109
+
110
+ Dir.exist?(dir_name).should be true
111
+ end
112
+
113
+ it "handles creating directories that don't exist, including many nested subdirectories" do
114
+ sub1 = "sub1"
115
+ sub2 = "sub1/sub2"
116
+ sub3 = "sub1/sub2/sub3"
117
+ @paths_to_nuke << sub1
118
+
119
+ create_subdirectory(sub1)
120
+ create_subdirectory(sub2)
121
+ create_subdirectory(sub3)
122
+
123
+ @setup.init_cfg_files do |item|
124
+ puts item[:message]
125
+
126
+ if item[:needs_confirmation]
127
+ item[:confirmation] = true
128
+ end
129
+ end
130
+
131
+ Dir.exist?(sub1).should be true
132
+ Dir.exist?(sub2).should be true
133
+ Dir.exist?(sub3).should be true
134
+ end
135
+
136
+ it "handles creating directories that do exist" do
137
+ sub1 = "sub1"
138
+ sub2 = "sub1/sub2"
139
+ sub3 = "sub1/sub2/sub3"
140
+ @paths_to_nuke << sub1
141
+
142
+ Dir.mkdir(sub1)
143
+ Dir.mkdir(sub2)
144
+ Dir.mkdir(sub3)
145
+
146
+ @setup.init_cfg_files do |item|
147
+ puts item[:message]
148
+
149
+ if item[:needs_confirmation] == true
150
+ item[:confirmation] = true
151
+ end
152
+ end
153
+
154
+ Dir.exist?(sub1).should be true
155
+ Dir.exist?(sub2).should be true
156
+ Dir.exist?(sub3).should be true
157
+ end
158
+
159
+ it "copies files that don't exist already" do
160
+ sub_dir = "config"
161
+ @paths_to_nuke << sub_dir
162
+
163
+ # A file to be copied around.
164
+ src_file_name = "spec/fixtures/empty_file.txt"
165
+
166
+ # A config file in a subdirectory
167
+ file1_path = "materiel/default_config_files/#{sub_dir}/config_file.txt"
168
+
169
+ # A config file in the root directory
170
+ file2_path = "materiel/default_config_files/config_file.txt"
171
+ @files_to_nuke << "config_file.txt"
172
+
173
+
174
+ create_subdirectory(sub_dir)
175
+
176
+ FileUtils.cp(src_file_name, file1_path)
177
+ FileUtils.cp(src_file_name, file2_path)
178
+
179
+ @setup.init_cfg_files do |item|
180
+ item[:needs_confirmation].should be false
181
+ end
182
+
183
+ File.exist?(file1_path).should be true
184
+ File.exist?(file2_path).should be true
185
+ end
186
+
187
+ it "doesn't overwrite existing files by default" do
188
+ sub1 = "config"
189
+ @paths_to_nuke << sub1
190
+
191
+ # The file that will try to be copied around from materiel
192
+ src_file_name = "spec/fixtures/file_with_content.txt"
193
+
194
+ # The file that will already be there.
195
+ existing_file_name = "spec/fixtures/empty_file.txt"
196
+
197
+ # Creating file path of default_cfg_file here for organization
198
+ file1_path = "materiel/default_config_files/#{sub1}/config_file.txt"
199
+
200
+ # Place spoof file in its 'production' location to be found by process
201
+ FileUtils.cp(existing_file_name, "./root.txt")
202
+ @files_to_nuke << "root.txt"
203
+
204
+
205
+ # Creating file path of default_cfg_file here for organization
206
+ Dir.mkdir("config")
207
+ @paths_to_nuke << "config"
208
+ file2_path = "materiel/default_config_files/root.txt"
209
+
210
+ # Place spoof file in its 'production' location to be found by process
211
+ FileUtils.cp(existing_file_name, "config/root.txt")
212
+
213
+ create_subdirectory(sub1)
214
+
215
+ # Now copy over files that are different than what exist. This will make it easier to make sure that the files
216
+ # were not overwritten.
217
+ FileUtils.cp(src_file_name, file1_path)
218
+ FileUtils.cp(src_file_name, file2_path)
219
+
220
+ @setup.init_cfg_files do |item|
221
+ if item[:needs_confirmation] == true
222
+ # Deny the process's request to write over the file.
223
+ item[:confirmation] = "n"
224
+ end
225
+ end
226
+
227
+ FileUtils.identical?(existing_file_name, "root.txt").should be true
228
+ FileUtils.identical?(existing_file_name, "config/root.txt").should be true
229
+ FileUtils.identical?(src_file_name, "root.txt").should be false
230
+ FileUtils.identical?(src_file_name, "config/root.txt").should be false
231
+ end
232
+
233
+ it "overwrites existing files if the user indicates yes" do
234
+ subdirectory = "config"
235
+ @paths_to_nuke << subdirectory
236
+
237
+ config_file_name = "config_file.txt"
238
+
239
+ # The file that will try to be copied around from materiel
240
+ src_file_name = "spec/fixtures/file_with_content.txt"
241
+
242
+ # The file that will already be there.
243
+ existing_file_name = "spec/fixtures/empty_file.txt"
244
+
245
+ # Place spoof file in its 'production' location to be found by process
246
+ FileUtils.cp(existing_file_name, "./#{config_file_name}")
247
+ @files_to_nuke << config_file_name
248
+
249
+ # Set up the existing subdir to be 'found' and ad its contents
250
+ Dir.mkdir("config")
251
+ @paths_to_nuke << "config"
252
+ FileUtils.cp(existing_file_name, "config/#{config_file_name}")
253
+
254
+ # Set up materiel and add a subdirectory
255
+ @setup.install
256
+ create_subdirectory(subdirectory)
257
+
258
+ # Now copy over files that are different than what exist. This will make it easier to make sure that the files
259
+ # were not overwritten.
260
+ FileUtils.cp(src_file_name, "materiel/default_config_files/#{subdirectory}/#{config_file_name}")
261
+ FileUtils.cp(src_file_name, "materiel/default_config_files/#{config_file_name}")
262
+
263
+ # Run init, answering 'y' to each time it asks of the files are to be overwritten
264
+ i = 0
265
+ @setup.init_cfg_files do |item|
266
+ if item[:needs_confirmation] == true
267
+ # Deny the process's request to write over the file.
268
+ item[:confirmation] = "y"
269
+ i += 1
270
+ end
271
+ end
272
+ i.should eq 2 # There should have been two files found and replaced.
273
+
274
+ FileUtils.identical?(src_file_name, config_file_name).should be true
275
+ FileUtils.identical?(src_file_name, "config/#{config_file_name}").should be true
276
+ FileUtils.identical?(existing_file_name, config_file_name).should be false
277
+ FileUtils.identical?(existing_file_name, "config/#{config_file_name}").should be false
278
+ end
279
+
280
+ it "overwrites all existing files if the user indicates all" do
281
+ subdirectory = "config"
282
+ @paths_to_nuke << subdirectory
283
+
284
+ config_file_name = "config_file.txt"
285
+
286
+ # The file that will try to be copied around from materiel
287
+ src_file_name = "spec/fixtures/file_with_content.txt"
288
+
289
+ # The file that will already be there.
290
+ existing_file_name = "spec/fixtures/empty_file.txt"
291
+
292
+ # Place spoof file in its 'production' location to be found by process
293
+ FileUtils.cp(existing_file_name, "./#{config_file_name}")
294
+ @files_to_nuke << config_file_name
295
+
296
+ # Set up the existing subdir to be 'found' and ad its contents
297
+ Dir.mkdir("config")
298
+ @paths_to_nuke << "config"
299
+ FileUtils.cp(existing_file_name, "config/#{config_file_name}")
300
+
301
+ # Set up materiel and add a subdirectory
302
+ @setup.install
303
+ create_subdirectory(subdirectory)
304
+
305
+ # Now copy over files that are different than what exist. This will make it easier to make sure that the files
306
+ # were not overwritten.
307
+ FileUtils.cp(src_file_name, "materiel/default_config_files/#{subdirectory}/#{config_file_name}")
308
+ FileUtils.cp(src_file_name, "materiel/default_config_files/#{config_file_name}")
309
+
310
+ # Run init, answering 'y' to each time it asks of the files are to be overwritten
311
+ i = 0
312
+ @setup.init_cfg_files do |item|
313
+ if item[:needs_confirmation] == true
314
+ # Deny the process's request to write over the file.
315
+ item[:confirmation] = "a"
316
+ i += 1
317
+ end
318
+ end
319
+ i.should eq 1 # There should have been one prompt
320
+
321
+ FileUtils.identical?(src_file_name, config_file_name).should be true
322
+ FileUtils.identical?(src_file_name, "config/#{config_file_name}").should be true
323
+ FileUtils.identical?(existing_file_name, config_file_name).should be false
324
+ FileUtils.identical?(existing_file_name, "config/#{config_file_name}").should be false
325
+ end
326
+
327
+ it "cancels the entire operation if (c) chosen" do
328
+ subdirectory = "config"
329
+ @paths_to_nuke << subdirectory
330
+
331
+ config_file_name = "config_file.txt"
332
+
333
+ # The file that will try to be copied around from materiel
334
+ src_file_name = "spec/fixtures/file_with_content.txt"
335
+
336
+ # The file that will already be there.
337
+ existing_file_name = "spec/fixtures/empty_file.txt"
338
+
339
+ # Place spoof file in its 'production' location to be found by process
340
+ FileUtils.cp(existing_file_name, "./#{config_file_name}")
341
+ @files_to_nuke << config_file_name
342
+
343
+ # Set up the existing subdir to be 'found' and ad its contents
344
+ Dir.mkdir("config")
345
+ @paths_to_nuke << "config"
346
+ FileUtils.cp(existing_file_name, "config/#{config_file_name}")
347
+
348
+ # Set up materiel and add a subdirectory
349
+ @setup.install
350
+ create_subdirectory(subdirectory)
351
+
352
+ # Now copy over files that are different than what exist. This will make it easier to make sure that the files
353
+ # were not overwritten.
354
+ FileUtils.cp(src_file_name, "materiel/default_config_files/#{subdirectory}/#{config_file_name}")
355
+ FileUtils.cp(src_file_name, "materiel/default_config_files/#{config_file_name}")
356
+
357
+ i = 0
358
+ @setup.init_cfg_files do |item|
359
+ i += 1
360
+ if item[:needs_confirmation] == true
361
+ # Cancel the whole deal.
362
+ item[:confirmation] = "c"
363
+ end
364
+ end
365
+ i.should eq 1 # There should have been one prompt
366
+ end
367
+ end
368
+ end
369
+
370
+ def create_subdirectory(subdirectory_name)
371
+ subdir_path = "#@default_config_files_path/#{subdirectory_name}"
372
+
373
+ if !Dir.exists?(subdir_path)
374
+ Dir.mkdir(subdir_path)
375
+ end
376
+ end
377
+ end
@@ -0,0 +1,4 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "materielize"
4
+
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: materielize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ray Parker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: thor
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: highline
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: A helper for default config files.
79
+ email:
80
+ - RayParkerBassPlayer@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rvmrc
87
+ - Gemfile
88
+ - LICENSE
89
+ - README.md
90
+ - Rakefile
91
+ - lib/materielize.rb
92
+ - lib/materielize/railtie.rb
93
+ - lib/materielize/version.rb
94
+ - lib/root.txt
95
+ - lib/tasks/materiel.rake
96
+ - lib/tasks/materiel.thor
97
+ - materielize.gemspec
98
+ - spec/fixtures/empty_file.txt
99
+ - spec/fixtures/file_with_content.txt
100
+ - spec/models/config_files_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: http://github.com/RayParkerBassPlayer/materielize
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: -2025525412337206457
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: -2025525412337206457
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.24
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Helps with the stowage and installation of default config files -- helpful
132
+ for dev and CI environments.
133
+ test_files:
134
+ - spec/fixtures/empty_file.txt
135
+ - spec/fixtures/file_with_content.txt
136
+ - spec/models/config_files_spec.rb
137
+ - spec/spec_helper.rb