rails_renamer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,9 +1,6 @@
1
- rails_renamer
2
- =============
3
- =======
4
1
  # RailsRenamer
5
2
 
6
- TODO: Write a gem description
3
+ A gem to help you rename your Rails application after creating it.
7
4
 
8
5
  ## Installation
9
6
 
@@ -21,7 +18,11 @@ Or install it yourself as:
21
18
 
22
19
  ## Usage
23
20
 
24
- TODO: Write usage instructions here
21
+ The easiest way to use the gem is to do the following:
22
+
23
+ 1. Add it to your application's Gemfile.
24
+ 2. Open the Rails console (rails c).
25
+ 3. Run the following command: `RailsRenamer.rename_current_application('./', new_application_name)` where `new_application_name` is your new desired app name.
25
26
 
26
27
  ## Contributing
27
28
 
data/lib/rails_renamer.rb CHANGED
@@ -5,9 +5,6 @@ require 'rails_renamer/file_repository'
5
5
  require 'rails_renamer/file_iterator'
6
6
  require 'rails_renamer/content_replacer'
7
7
 
8
- require 'pry'
9
-
10
-
11
8
  module RailsRenamer
12
9
  def self.rename_current_application(application_root, new_app_name)
13
10
  application_file = application_root + RailsRenamer::FileRepository.application_file
@@ -2,20 +2,26 @@ module RailsRenamer
2
2
  class ContentReplacer
3
3
  def self.find_and_replace_application_name(file_name, current_name, new_app_name)
4
4
  begin
5
- file_stream = File.open(file_name, 'r+')
6
- rescue Errno::ENOENT => e
5
+ file_stream = File.open(file_name, 'r')
6
+ rescue Errno::ENOENT
7
7
  puts "The specified file does not exist: #{file_name}"
8
8
  return
9
9
  end
10
10
 
11
11
  contents = file_stream.read
12
-
13
12
  contents.gsub!(current_name, new_app_name)
14
13
 
15
- File.truncate(file_name, 0)
14
+ File.delete(file_name)
15
+ write_new_file(file_name, contents)
16
+ contents
17
+ end
18
+
19
+ private
20
+
21
+ def self.write_new_file(file_name, contents)
22
+ file_stream = File.open(file_name, 'w')
16
23
  file_stream.write(contents)
17
24
  file_stream.close
18
- contents
19
25
  end
20
26
  end
21
27
  end
@@ -1,3 +1,3 @@
1
1
  module RailsRenamer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -7,8 +7,9 @@ describe RailsRenamer::ContentReplacer do
7
7
  let(:file) { double(:file, read: file_contents, write: nil, close: nil) }
8
8
 
9
9
  before do
10
- File.stub(:open).with('file/to/parse', 'r+') { file }
11
- File.stub(:truncate).with('file/to/parse', 0)
10
+ File.stub(:open).with('file/to/parse', 'r') { file }
11
+ File.stub(:open).with('file/to/parse', 'w') { file }
12
+ File.stub(:delete)
12
13
  end
13
14
 
14
15
  it "replaces the existing file name with the given name" do
@@ -25,8 +26,8 @@ describe RailsRenamer::ContentReplacer do
25
26
  new_contents.should == "BAZ baz foo FOO Bar"
26
27
  end
27
28
 
28
- it "truncates the file" do
29
- File.should_receive(:truncate).with('file/to/parse', 0)
29
+ it "deletes the file" do
30
+ File.should_receive(:delete)
30
31
  RailsRenamer::ContentReplacer.
31
32
  find_and_replace_application_name('file/to/parse', 'Foo', 'Bar')
32
33
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsRenamer" do
4
+ let(:files_to_check) { ['config/application.rb',
5
+ 'config/environment.rb',
6
+ 'config/environments/development.rb',
7
+ 'config/environments/production.rb',
8
+ 'config/environments/test.rb',
9
+ 'config/initializers/secret_token.rb',
10
+ 'config/initializers/session_store.rb',
11
+ 'config/mongoid.yml',
12
+ 'config/routes.rb',
13
+ 'config.ru',
14
+ 'Rakefile',
15
+ 'app/views/layouts/application.html.erb']
16
+ }
17
+
18
+ after do
19
+ replace_test_rails_application
20
+ end
21
+
22
+ it "renames the classes and references in a rails application" do
23
+ application_root = 'spec/integrations/test_rails_app/'
24
+ new_application_name = 'NewApplication'
25
+
26
+ RailsRenamer.rename_current_application(application_root, new_application_name)
27
+
28
+ files_to_check.each do |file_name|
29
+ begin
30
+ file_contents = File.open("#{Dir.pwd + '/'}#{application_root}#{file_name}", 'r').read
31
+ rescue Errno::ENOENT => e
32
+ puts "Skipping unused file: #{file_name}"
33
+ next
34
+ end
35
+
36
+ file_contents.should be
37
+ file_contents.should_not include("DefaultApp")
38
+ end
39
+ end
40
+
41
+ def replace_test_rails_application
42
+ `rm -rf spec/integrations/test_rails_app`
43
+ `cp -r spec/integrations/original_rails_app/ spec/integrations/test_rails_app`
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_renamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -68,6 +68,7 @@ files:
68
68
  - spec/application_file_parser_spec.rb
69
69
  - spec/content_replacer_spec.rb
70
70
  - spec/file_iterator_spec.rb
71
+ - spec/integrations/rails_renamer_spec.rb
71
72
  - spec/original_name_locator_spec.rb
72
73
  - spec/spec_helper.rb
73
74
  homepage: https://github.com/joeletizia/rails_renamer
@@ -99,5 +100,6 @@ test_files:
99
100
  - spec/application_file_parser_spec.rb
100
101
  - spec/content_replacer_spec.rb
101
102
  - spec/file_iterator_spec.rb
103
+ - spec/integrations/rails_renamer_spec.rb
102
104
  - spec/original_name_locator_spec.rb
103
105
  - spec/spec_helper.rb