rails_renamer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/lib/rails_renamer/application_file_parser.rb +15 -0
- data/lib/rails_renamer/content_replacer.rb +21 -0
- data/lib/rails_renamer/file_iterator.rb +14 -0
- data/lib/rails_renamer/file_repository.rb +24 -0
- data/lib/rails_renamer/original_name_locator.rb +11 -0
- data/lib/rails_renamer/version.rb +3 -0
- data/lib/rails_renamer.rb +22 -0
- data/rails_renamer.gemspec +23 -0
- data/spec/application_file_parser_spec.rb +24 -0
- data/spec/content_replacer_spec.rb +36 -0
- data/spec/file_iterator_spec.rb +22 -0
- data/spec/original_name_locator_spec.rb +14 -0
- data/spec/spec_helper.rb +20 -0
- metadata +103 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Joe Letizia
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Joe Letizia
|
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,32 @@
|
|
1
|
+
rails_renamer
|
2
|
+
=============
|
3
|
+
=======
|
4
|
+
# RailsRenamer
|
5
|
+
|
6
|
+
TODO: Write a gem description
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'rails_renamer'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rails_renamer
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RailsRenamer
|
2
|
+
class ApplicationFileParser
|
3
|
+
def initialize(application_file_name)
|
4
|
+
@application_file_name = application_file_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def application_name
|
8
|
+
file = File.open(@application_file_name, "r")
|
9
|
+
contents = file.read
|
10
|
+
|
11
|
+
module_string = contents[/module .*$/]
|
12
|
+
module_string.gsub('module ', '')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RailsRenamer
|
2
|
+
class ContentReplacer
|
3
|
+
def self.find_and_replace_application_name(file_name, current_name, new_app_name)
|
4
|
+
begin
|
5
|
+
file_stream = File.open(file_name, 'r+')
|
6
|
+
rescue Errno::ENOENT => e
|
7
|
+
puts "The specified file does not exist: #{file_name}"
|
8
|
+
return
|
9
|
+
end
|
10
|
+
|
11
|
+
contents = file_stream.read
|
12
|
+
|
13
|
+
contents.gsub!(current_name, new_app_name)
|
14
|
+
|
15
|
+
File.truncate(file_name, 0)
|
16
|
+
file_stream.write(contents)
|
17
|
+
file_stream.close
|
18
|
+
contents
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RailsRenamer
|
2
|
+
class FileIterator
|
3
|
+
def initialize(file_repository, new_app_name)
|
4
|
+
@file_repository = file_repository
|
5
|
+
@new_app_name = new_app_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_all
|
9
|
+
@file_repository.files_to_rename.each do |file|
|
10
|
+
RailsRenamer::ContentReplacer.find_and_replace_application_name(file, @new_app_name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RailsRenamer
|
2
|
+
class FileRepository
|
3
|
+
FILES_TO_RENAME = ['config/application.rb',
|
4
|
+
'config/environment.rb',
|
5
|
+
'config/environments/development.rb',
|
6
|
+
'config/environments/production.rb',
|
7
|
+
'config/environments/test.rb',
|
8
|
+
'config/initializers/secret_token.rb',
|
9
|
+
'config/initializers/session_store.rb',
|
10
|
+
'config/mongoid.yml',
|
11
|
+
'config/routes.rb',
|
12
|
+
'config.ru',
|
13
|
+
'Rakefile',
|
14
|
+
'app/views/layouts/application.html.erb']
|
15
|
+
|
16
|
+
def self.files_to_rename
|
17
|
+
FILES_TO_RENAME
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.application_file
|
21
|
+
'config/application.rb'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RailsRenamer
|
2
|
+
class OriginalNameLocator
|
3
|
+
def self.original_name(application_root)
|
4
|
+
app_file = application_root + RailsRenamer::FileRepository.application_file
|
5
|
+
|
6
|
+
parser = ApplicationFileParser.new(app_file)
|
7
|
+
|
8
|
+
parser.application_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "rails_renamer/version"
|
2
|
+
require 'rails_renamer/original_name_locator'
|
3
|
+
require "rails_renamer/application_file_parser"
|
4
|
+
require 'rails_renamer/file_repository'
|
5
|
+
require 'rails_renamer/file_iterator'
|
6
|
+
require 'rails_renamer/content_replacer'
|
7
|
+
|
8
|
+
require 'pry'
|
9
|
+
|
10
|
+
|
11
|
+
module RailsRenamer
|
12
|
+
def self.rename_current_application(application_root, new_app_name)
|
13
|
+
application_file = application_root + RailsRenamer::FileRepository.application_file
|
14
|
+
current_name = RailsRenamer::ApplicationFileParser.new(application_file).application_name
|
15
|
+
|
16
|
+
FileRepository.files_to_rename.each do |file_name|
|
17
|
+
full_file_path = application_root + file_name
|
18
|
+
ContentReplacer.find_and_replace_application_name(full_file_path, current_name, new_app_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_renamer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_renamer"
|
8
|
+
spec.version = RailsRenamer::VERSION
|
9
|
+
spec.authors = ["Joe Letizia"]
|
10
|
+
spec.email = ["joe.letizia@gmail.com"]
|
11
|
+
spec.description = %q{Rename your rails project with ease.}
|
12
|
+
spec.summary = %q{Rename your rails project.}
|
13
|
+
spec.homepage = "https://github.com/joeletizia/rails_renamer"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsRenamer::ApplicationFileParser do
|
4
|
+
let(:app_file) { 'file/to/parse' }
|
5
|
+
let(:parser) { RailsRenamer::ApplicationFileParser.new(app_file) }
|
6
|
+
|
7
|
+
describe "#application_name" do
|
8
|
+
|
9
|
+
let(:file) { double(:file) }
|
10
|
+
let(:file_contents) { %Q[ module DefaultApp
|
11
|
+
class Application < Rails::Application
|
12
|
+
end
|
13
|
+
end] }
|
14
|
+
|
15
|
+
before do
|
16
|
+
File.stub(:open).with('file/to/parse', "r") { file }
|
17
|
+
file.stub(:read) { file_contents }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the appropriate constant defining the application" do
|
21
|
+
parser.application_name.should == 'DefaultApp'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsRenamer::ContentReplacer do
|
4
|
+
|
5
|
+
describe "#find_and_replace_application_name" do
|
6
|
+
let(:file_contents) { "BAZ baz foo FOO Foo" }
|
7
|
+
let(:file) { double(:file, read: file_contents, write: nil, close: nil) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
File.stub(:open).with('file/to/parse', 'r+') { file }
|
11
|
+
File.stub(:truncate).with('file/to/parse', 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "replaces the existing file name with the given name" do
|
15
|
+
file_contents.should_receive(:gsub!).with('Foo', 'Bar')
|
16
|
+
|
17
|
+
RailsRenamer::ContentReplacer.
|
18
|
+
find_and_replace_application_name('file/to/parse', 'Foo', 'Bar')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the contents of the file" do
|
22
|
+
new_contents = RailsRenamer::ContentReplacer.
|
23
|
+
find_and_replace_application_name('file/to/parse', 'Foo', 'Bar')
|
24
|
+
|
25
|
+
new_contents.should == "BAZ baz foo FOO Bar"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "truncates the file" do
|
29
|
+
File.should_receive(:truncate).with('file/to/parse', 0)
|
30
|
+
RailsRenamer::ContentReplacer.
|
31
|
+
find_and_replace_application_name('file/to/parse', 'Foo', 'Bar')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsRenamer::FileIterator do
|
4
|
+
before do
|
5
|
+
RailsRenamer::FileRepository.stub(:files_to_rename) { files }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#parse_all' do
|
9
|
+
let(:file_repository) { RailsRenamer::FileRepository }
|
10
|
+
let(:iterator) { RailsRenamer::FileIterator.new(file_repository, 'bar') }
|
11
|
+
let(:files) { ['foo1', 'foo2'] }
|
12
|
+
|
13
|
+
it "parses and replaces the application name in all files" do
|
14
|
+
files.each do |file|
|
15
|
+
RailsRenamer::ContentReplacer.should_receive(:find_and_replace_application_name).with(file, 'bar')
|
16
|
+
end
|
17
|
+
|
18
|
+
iterator.parse_all
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsRenamer::OriginalNameLocator do
|
4
|
+
describe "original_name" do
|
5
|
+
let(:parser) { double(:parser) }
|
6
|
+
|
7
|
+
it "uses the ApplicationFileParser to return the app name" do
|
8
|
+
RailsRenamer::ApplicationFileParser.stub(:new).with('root/path/config/application.rb') { parser }
|
9
|
+
parser.stub(:application_name) { 'bar' }
|
10
|
+
|
11
|
+
RailsRenamer::OriginalNameLocator.original_name('root/path/').should == 'bar'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'rails_renamer'
|
8
|
+
require 'pry'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_renamer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joe Letizia
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
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: '1.3'
|
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
|
+
description: Rename your rails project with ease.
|
47
|
+
email:
|
48
|
+
- joe.letizia@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- lib/rails_renamer.rb
|
61
|
+
- lib/rails_renamer/application_file_parser.rb
|
62
|
+
- lib/rails_renamer/content_replacer.rb
|
63
|
+
- lib/rails_renamer/file_iterator.rb
|
64
|
+
- lib/rails_renamer/file_repository.rb
|
65
|
+
- lib/rails_renamer/original_name_locator.rb
|
66
|
+
- lib/rails_renamer/version.rb
|
67
|
+
- rails_renamer.gemspec
|
68
|
+
- spec/application_file_parser_spec.rb
|
69
|
+
- spec/content_replacer_spec.rb
|
70
|
+
- spec/file_iterator_spec.rb
|
71
|
+
- spec/original_name_locator_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: https://github.com/joeletizia/rails_renamer
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.25
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Rename your rails project.
|
98
|
+
test_files:
|
99
|
+
- spec/application_file_parser_spec.rb
|
100
|
+
- spec/content_replacer_spec.rb
|
101
|
+
- spec/file_iterator_spec.rb
|
102
|
+
- spec/original_name_locator_spec.rb
|
103
|
+
- spec/spec_helper.rb
|