jumpstart 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :jumpstart_version_major: 0
3
3
  :jumpstart_version_minor: 6
4
- :jumpstart_version_patch: 4
4
+ :jumpstart_version_patch: 5
@@ -122,36 +122,38 @@ module JumpStart::FileTools
122
122
  # Hello there NAME from COUNTRY
123
123
  # Will also replace strings present in the target_file path. so if the method call looked like: FileUtils.replace_strings(target_file, :name => "Ian", :country => "England")
124
124
  # and target_file was: /Users/name/Sites/country the strings matching NAME and COUNTRY inside the file would be swapped out and then a new file at the path: /Users/Ian/Sites/England would be created and populated with the contents. The file at the previous path would be deleted.
125
- # Finally if you specify a symbol and append _CLASS in the template, that instance will be replace with a capitalized version of the string.
126
-
127
- #TODO REMOVE DIRECTORY PATH FROM FILE NAME SO THAT FILE CREATION REMAINS CONSISTENT
128
-
125
+ # Finally if you specify a symbol and append _CLASS in the template, that instance will be replace with a capitalized version of the string.
129
126
  def replace_strings(target_file, args)
130
127
  if File.file?(target_file)
131
128
  permissions = File.executable?(target_file)
132
- txt = IO.read(target_file)
129
+ original_txt = IO.read(target_file)
133
130
  old_dir = target_file.sub(/\/\w+\.*\w*$/, '')
134
- new_file = target_file.gsub(/#{old_dir}/, '')
131
+ new_file = target_file.gsub(/#{old_dir}\//, '')
135
132
  new_dir = old_dir.dup
133
+ new_txt = original_txt.dup
136
134
  args.each do |x, y|
137
- txt.gsub!(/#{x.to_s.upcase}_CLASS/, y.capitalize)
138
- txt.gsub!(/#{x.to_s.upcase}/, y)
139
- new_dir.gsub!(/\/#{x.to_s.downcase}/, "/#{y}")
135
+ new_txt.gsub!(/#{x.to_s.upcase}_CLASS/, y.capitalize)
136
+ new_txt.gsub!(/#{x.to_s.upcase}/, y)
137
+ new_dir.gsub!(/#{x.to_s.downcase}/, y)
140
138
  new_file.gsub!(/#{x.to_s.downcase}/, y)
141
139
  end
142
- if old_dir.to_s != new_dir.to_s
140
+ if (old_dir <=> new_dir) != 0 && !File.directory?(new_dir)
143
141
  FileUtils.mkdir_p(new_dir)
144
142
  end
145
- File.open(FileUtils.join_paths(new_dir, new_file), "w+") do |file|
146
- file.puts txt
143
+ File.open("#{new_dir}/#{new_file}", "w") do |file|
144
+ file.puts new_txt
147
145
  file.chmod(0755) if permissions
148
146
  end
149
- FileUtils.rm(target_file)
150
- if File.directory?(old_dir)
151
- if (Dir.entries(old_dir) - JumpStart::IGNORE_DIRS).empty?
152
- FileUtils.remove_dir(old_dir)
147
+ if (target_file <=> "#{new_dir}/#{new_file}") != 0
148
+ FileUtils.rm(target_file)
149
+ if File.directory?(old_dir)
150
+ if (Dir.entries(old_dir) - ['.', '..']).empty?
151
+ FileUtils.remove_dir(old_dir)
152
+ end
153
153
  end
154
- end
154
+ end
155
+ else
156
+ puts "#{target_file} is NOT a file"
155
157
  end
156
158
  end
157
159
 
@@ -1197,6 +1197,8 @@ class TestJumpstartBase < Test::Unit::TestCase
1197
1197
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_whole_file_with_extension.txt")
1198
1198
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_whole_file_without_extension")
1199
1199
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_1.txt")
1200
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_replace_strings/replace_strings_1.rb")
1201
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_replace_strings/replace_strings_2.txt")
1200
1202
  assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_L._test_append_to_end_of_file_remove_last_line_1.txt")
1201
1203
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
1202
1204
  assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_l._test_append_to_end_of_file_remove_last_line_2.txt")
@@ -236,21 +236,19 @@ class TestJumpstartFileTools < Test::Unit::TestCase
236
236
 
237
237
  setup do
238
238
  @source_file = IO.readlines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb")
239
+ @target_file_1 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb"
239
240
  @target_file_2 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/replace_strings_test_app_name.rb"
240
241
  @target_file_3 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name/app_name_replace_strings_test.txt"
242
+ @target_file_4 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name/Rakefile"
241
243
  @new_file_2 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/replace_strings_test_bungle.rb"
242
244
  @new_file_3 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/bungle/bungle_replace_strings_test.txt"
243
- @target_files = [@target_file_2, @target_file_3]
245
+ @target_files = [@target_file_1, @target_file_2, @target_file_3]
244
246
  FileUtils.mkdir_p("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
245
247
  @target_files.each do |t|
246
- File.open(t, 'w+') do |file|
248
+ File.open(t, 'w') do |file|
247
249
  file.puts @source_file
248
250
  end
249
251
  end
250
- @target_file_4 = "#{JumpStart::ROOT_PATH}/test/destination_dir/config_capistrano.rb"
251
- File.open(@target_file_4, 'w+') do |file|
252
- file.puts @source_file
253
- end
254
252
  end
255
253
 
256
254
  teardown do
@@ -265,9 +263,24 @@ class TestJumpstartFileTools < Test::Unit::TestCase
265
263
  FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
266
264
  end
267
265
  end
266
+
267
+ should "replace strings with replace_strings method if the path does not contain the replacement strings and only one replacement string is provided" do
268
+ FileUtils.replace_strings(@target_file_1, {:app_name => 'test_app'})
269
+ file = IO.readlines(@target_file_1)
270
+ assert_equal "set :application, 'test_app'\n", file[0]
271
+ assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
272
+ end
273
+
274
+ should "replace strings with replace_strings method if the path does not contain the replacement strings and more than one replacement string is provided" do
275
+ FileUtils.replace_strings(@target_file_1, {:app_name => 'test_app', :REMOTE_SERVER => 'remote_box'})
276
+ file = IO.readlines(@target_file_1)
277
+ assert_equal "set :application, 'test_app'\n", file[0]
278
+ assert_equal "set :domain, 'remote_box'\n", file[1]
279
+ assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
280
+ end
268
281
 
269
282
  should "replace strings inside the target path if the target is a file and there is more than one argument." do
270
- FileUtils.replace_strings(@target_file_2, :app_name => 'bungle', :remote_server => 'boxy')
283
+ FileUtils.replace_strings(@target_file_2, {:app_name => 'bungle', :remote_server => 'boxy'})
271
284
  file = IO.readlines(@new_file_2)
272
285
  assert_equal "set :application, 'bungle'\n", file[0]
273
286
  assert_equal "set :domain, 'boxy'\n", file[1]
@@ -277,7 +290,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
277
290
  end
278
291
 
279
292
  should "replace strings inside the target path if the target is a file and there is more than one argument and the replacement string is found in the directory structure." do
280
- FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
293
+ FileUtils.replace_strings(@target_file_3, {:app_name => 'bungle', :remote_server => 'boxy'})
281
294
  file = IO.readlines(@new_file_3)
282
295
  assert_equal "set :application, 'bungle'\n", file[0]
283
296
  assert_equal "set :domain, 'boxy'\n", file[1]
@@ -287,7 +300,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
287
300
  end
288
301
 
289
302
  should "replace strings that have _CLASS appended to them with a capitalised version of the replacement string." do
290
- FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
303
+ FileUtils.replace_strings(@target_file_3, {:app_name => 'bungle', :remote_server => 'boxy'})
291
304
  file = IO.readlines(@new_file_3)
292
305
  assert_equal "set :application, 'bungle'\n", file[0]
293
306
  assert_equal "set :domain, 'boxy'\n", file[1]
@@ -299,13 +312,13 @@ class TestJumpstartFileTools < Test::Unit::TestCase
299
312
  end
300
313
 
301
314
  should "remove old dirs when empty after string replacement" do
302
- FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
315
+ FileUtils.replace_strings(@target_file_3, {:app_name => 'bungle', :remote_server => 'boxy'})
303
316
  assert !File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
304
317
  end
305
318
 
306
319
  should "not remove old dirs after string replacement if they are not empty" do
307
320
  FileUtils.touch("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name/another_file.txt")
308
- FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
321
+ FileUtils.replace_strings(@target_file_3, {:app_name => 'bungle', :remote_server => 'boxy'})
309
322
  assert File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
310
323
  assert File.exists?(@new_file_3)
311
324
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 4
9
- version: 0.6.4
8
+ - 5
9
+ version: 0.6.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ian Alexander Wood (i0n)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-07 00:00:00 +01:00
17
+ date: 2010-09-08 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,6 @@ files:
64
64
  - lib/jumpstart/stringtools.rb
65
65
  - lib/jumpstart.rb
66
66
  - source_templates/template_config.yml
67
- - test/destination_dir/config_capistrano.rb
68
67
  - test/fake_nginx_path/local_nginx_1.conf
69
68
  - test/fake_nginx_path/remote_nginx_1.conf
70
69
  - test/helper.rb
@@ -1,65 +0,0 @@
1
- set :application, 'APP_NAME'
2
- set :domain, 'REMOTE_SERVER'
3
- set :user, 'i0n'
4
-
5
- set :repository, "#{user}@#{domain}:/home/#{user}/git/#{application}.git"
6
-
7
- role :app, domain # This may be the same as the `Web` server
8
- role :web, domain # Your HTTP server, Apache/etc
9
- role :db, domain , :primary => true # This is where Rails migrations will run
10
-
11
- set :scm_verbose, true
12
-
13
- set :scm, :git
14
- set :scm_username, user
15
- set :runner, user
16
- set :use_sudo, false
17
- set :branch, "master"
18
- set :deploy_via, :checkout
19
- set :git_shallow_clone, 1
20
- set :deploy_to, "/home/#{user}/sites/#{application}"
21
- default_run_options[:pty] = true
22
-
23
- namespace :deploy do
24
- #task which causes Passenger to initiate a restart
25
- task :restart do
26
- run "mkdir -p #{release_path}/tmp && touch #{release_path}/tmp/restart.txt"
27
- end
28
-
29
- namespace :db do
30
-
31
- desc "Create database for the production environment using the servers rake db:setup task.\n Loads the schema, and initializes with the seed data"
32
- task :setup do
33
- run "cd #{current_path}; rake db:setup RAILS_ENV=production"
34
- end
35
-
36
- desc "Populates the production database using lib/tasks/populate which I will use as my own internal convention for this process"
37
- task :populate do
38
- run "cd #{current_path}; rake db:populate RAILS_ENV=production"
39
- end
40
-
41
- end
42
-
43
- desc "Task to set up the remote Nginx server for app deployment"
44
- task :nginx do
45
- run "#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf APP_NAME"
46
- end
47
-
48
- desc "Create bare remote git repo then add remote origin to local git repo and push to remote"
49
- task :git do
50
- run "cd /home/#{user}/git; mkdir #{application}.git; cd #{application}.git; git init --bare"
51
- `git remote add origin ssh://#{user}@#{domain}/~/git/#{application}.git`
52
- `git push origin master`
53
- end
54
-
55
- end
56
-
57
- # Reminder of default actions for cap deploy:
58
- # deploy:update_code
59
- # deploy:symlink
60
- # deploy:restart
61
-
62
- # eg: after 'deploy:symlink', 'deploy:restart'
63
-
64
- # This is a test string APP_NAME_CLASS
65
- # This is a test string REMOTE_SERVER_CLASS