namer 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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/bin/namer +6 -0
- data/lib/namer.rb +61 -0
- data/namer.gemspec +24 -0
- data/spec/namer_spec.rb +24 -0
- data/spec/spec_helper.rb +7 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 663e385d757df24b6440c7d7e92ddd6b2202e11e
|
4
|
+
data.tar.gz: 2ed6e778eb932f43ba439c7a7cd9867f7a4943c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1967de4a7095b418c48ff541aeec312a753b1eb7368e8e82301a493b6eee83859d85b046c84bb6f5a7c5f7436d741bd42211219e97ab55c02dd5c85ef0fd44b1
|
7
|
+
data.tar.gz: 8298a1c94447cd3c53e3695fbeac6e714c9d91f400e9304ff9bcb6dbb5847ea694af792f728bd90a389887fcaf7f5a4100408609df6a84cd21a117c4ba2cd29f
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
namer
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013
|
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,42 @@
|
|
1
|
+
##Namer
|
2
|
+
|
3
|
+
Rename your project with a single command.
|
4
|
+
|
5
|
+
###Install
|
6
|
+
|
7
|
+
gem install namer
|
8
|
+
|
9
|
+
###Rename project
|
10
|
+
|
11
|
+
cd project
|
12
|
+
namer project:new_project Project:NewProject
|
13
|
+
|
14
|
+
This replaces code and file names:
|
15
|
+
|
16
|
+
* `project` becomes `new_project`
|
17
|
+
* `Project` becomes `NewProject`
|
18
|
+
|
19
|
+
It will also replace the keywords on the git origin URL (if git repo).
|
20
|
+
|
21
|
+
###Replace file via inline comment
|
22
|
+
|
23
|
+
puts "replace me"
|
24
|
+
|
25
|
+
# -- replace
|
26
|
+
# raise "replaced by me"
|
27
|
+
|
28
|
+
After running `namer`, this ruby file would only contain `raise "replace by me"`.
|
29
|
+
|
30
|
+
This feature allows [gem_template](https://github.com/winton/gem_template) to self-replicate without copying the code used to self-replicate :).
|
31
|
+
|
32
|
+
###Contribute
|
33
|
+
|
34
|
+
[Create an issue](https://github.com/winton/namer/issues/new) to discuss template changes.
|
35
|
+
|
36
|
+
Pull requests for template changes and new branches are even better.
|
37
|
+
|
38
|
+
###Stay up to date
|
39
|
+
|
40
|
+
[Star this project](https://github.com/winton/namer#) on Github.
|
41
|
+
|
42
|
+
[Follow Winton Welsh](http://twitter.com/intent/user?screen_name=wintonius) on Twitter.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/namer
ADDED
data/lib/namer.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class Namer
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
path = Dir.pwd
|
7
|
+
args.each do |arg|
|
8
|
+
next unless arg.include?(':')
|
9
|
+
@from, @to = arg.split(':')
|
10
|
+
rename unless args.include?('--no-rename')
|
11
|
+
replace unless args.include?('--no-replace')
|
12
|
+
rename_remote unless args.include?('--no-remote')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def dir(pattern)
|
17
|
+
files = Dir.glob(pattern, File::FNM_DOTMATCH)
|
18
|
+
files -= %w[. ..]
|
19
|
+
files.reject { |f| f =~ /^.git/ }
|
20
|
+
end
|
21
|
+
|
22
|
+
def from_regex
|
23
|
+
/([^a-zA-Z]|^)#{@from}([^a-zA-Z]|$)/
|
24
|
+
end
|
25
|
+
|
26
|
+
def gsub(str)
|
27
|
+
str.gsub(from_regex, "\\1#{@to}\\2")
|
28
|
+
end
|
29
|
+
|
30
|
+
def rename_remote
|
31
|
+
url = remote
|
32
|
+
new_url = gsub(url)
|
33
|
+
return if url == new_url
|
34
|
+
`git remote rm origin`
|
35
|
+
`git remote add origin #{new_url}`
|
36
|
+
end
|
37
|
+
|
38
|
+
def rename
|
39
|
+
files = dir("**/#{@from}*")
|
40
|
+
begin
|
41
|
+
if a = files.pop
|
42
|
+
b = a.split('/')
|
43
|
+
b[-1] = gsub(b[-1])
|
44
|
+
FileUtils.mv(a, b.join('/'))
|
45
|
+
end
|
46
|
+
end while files.length > 0
|
47
|
+
end
|
48
|
+
|
49
|
+
def remote
|
50
|
+
`git remote show -n origin`.match(/Push\s+URL:\s+(\S+)/)[1] rescue nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def replace
|
54
|
+
dir("**/*").each do |path|
|
55
|
+
next unless File.file?(path)
|
56
|
+
text = File.read(path)
|
57
|
+
next unless (text =~ from_regex rescue nil)
|
58
|
+
File.open(path, 'w') { |f| f.write(gsub(text)) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/namer.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "namer"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Winton Welsh"]
|
9
|
+
spec.email = ["mail@wintoni.us"]
|
10
|
+
spec.description = %q{Project template manager}
|
11
|
+
spec.summary = %q{Project template manager.}
|
12
|
+
spec.homepage = "https://github.com/winton/namer"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "simplecov"
|
24
|
+
end
|
data/spec/namer_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Namer do
|
4
|
+
it "should work" do
|
5
|
+
fixture = "#{$root}/spec/fixture"
|
6
|
+
|
7
|
+
FileUtils.rm_rf(fixture)
|
8
|
+
FileUtils.mkdir_p("#{fixture}/project")
|
9
|
+
|
10
|
+
File.open("#{fixture}/project/project.rb", 'w') do |f|
|
11
|
+
f.write("project\nProject\nMyProject")
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir.chdir(fixture)
|
15
|
+
|
16
|
+
`git init .`
|
17
|
+
`git remote add origin https://github.com/winton/project.git`
|
18
|
+
|
19
|
+
namer = Namer.new([ "project:new_project", "Project:NewProject" ])
|
20
|
+
namer.remote.should == "https://github.com/winton/new_project.git"
|
21
|
+
|
22
|
+
File.read("#{fixture}/new_project/new_project.rb").should == "new_project\nNewProject\nMyProject"
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: namer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Winton Welsh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Project template manager
|
70
|
+
email:
|
71
|
+
- mail@wintoni.us
|
72
|
+
executables:
|
73
|
+
- namer
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .ruby-gemset
|
79
|
+
- .ruby-version
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/namer
|
85
|
+
- lib/namer.rb
|
86
|
+
- namer.gemspec
|
87
|
+
- spec/namer_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/winton/namer
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.0.3
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Project template manager.
|
113
|
+
test_files:
|
114
|
+
- spec/namer_spec.rb
|
115
|
+
- spec/spec_helper.rb
|