another 0.0.3 → 0.0.4
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/another.gemspec +4 -2
- data/lib/another/confirmer.rb +18 -0
- data/lib/another/options.rb +44 -0
- data/lib/another/runner.rb +47 -32
- data/lib/another.rb +2 -2
- data/lib/core_ext/string.rb +10 -2
- data/spec/another_spec.rb +43 -14
- data/templates/{README.textile → ruby/README.textile} +0 -0
- data/templates/{lib → ruby/lib}/PROJECT/.gitignore +0 -0
- data/templates/{lib/PROJECT.rb.erb → ruby/lib/PROJECT.rb} +0 -0
- data/templates/ruby/manifest.txt +8 -0
- data/templates/{spec/PROJECT_spec.rb.erb → ruby/spec/PROJECT_spec.rb} +0 -0
- data/templates/{spec/spec_helper.rb.erb → ruby/spec/spec_helper.rb} +0 -0
- data/templates/sinatra/app.rb +6 -0
- data/templates/sinatra/manifest.txt +9 -0
- data/templates/sinatra/public/.gitignore +0 -0
- data/templates/sinatra/spec/.gitignore +0 -0
- data/templates/sinatra/spec/PROJECT_spec.rb +12 -0
- data/templates/sinatra/spec/spec_helper.rb +13 -0
- data/templates/sinatra/views/.gitignore +0 -0
- metadata +68 -24
data/another.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{another}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Pat Nakajima"]
|
@@ -10,7 +10,9 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.default_executable = %q{another}
|
11
11
|
s.email = %q{patnakajima@gmail.com}
|
12
12
|
s.executables = ["another"]
|
13
|
-
s.files = Dir
|
13
|
+
s.files = Dir.glob('**/**/**/**/**/**', File::FNM_DOTMATCH) \
|
14
|
+
.reject { |f| f =~ /\.git\// } \
|
15
|
+
.reject { |f| f =~ /^\.{1,2}$/ }
|
14
16
|
s.require_paths = ["lib"]
|
15
17
|
s.rubygems_version = %q{1.3.0}
|
16
18
|
s.summary = %q{My new Ruby project generator}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Another
|
2
|
+
module Confirmer
|
3
|
+
def confirmed?
|
4
|
+
say "Warning: Creating new projects makes you vulnerable to mockery.".bold
|
5
|
+
answer ? true : begin
|
6
|
+
say "Probably for the best."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def answer
|
13
|
+
ask "Are you sure you want to create a new project? ".bold do |answer|
|
14
|
+
answer =~ /^y/i
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Another
|
5
|
+
class Options
|
6
|
+
attr_reader :template, :project_name, :target
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
@args = args.dup
|
10
|
+
process!
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def process!
|
16
|
+
options = OpenStruct.new
|
17
|
+
options.template = "ruby"
|
18
|
+
|
19
|
+
opts = OptionParser.new do |opts|
|
20
|
+
opts.banner = "Usage: another [options] project-name"
|
21
|
+
|
22
|
+
opts.on("-t", "--template TEMPLATE", "Specify a template (default: Ruby)") do |template|
|
23
|
+
options.template = template
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
27
|
+
puts opts
|
28
|
+
exit!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.parse!(@args)
|
33
|
+
|
34
|
+
if @args.empty?
|
35
|
+
puts opts
|
36
|
+
exit!
|
37
|
+
else
|
38
|
+
@target = @args.shift
|
39
|
+
@template = options.template
|
40
|
+
@project_name = File.basename(target)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/another/runner.rb
CHANGED
@@ -1,71 +1,86 @@
|
|
1
1
|
module Another
|
2
2
|
class Runner
|
3
|
+
attr_reader :options
|
4
|
+
|
5
|
+
include Another::Confirmer
|
6
|
+
|
3
7
|
def initialize(args)
|
4
|
-
@
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
@options = Options.new(args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform!
|
12
|
+
@performing = true
|
13
|
+
|
14
|
+
return unless confirmed?
|
15
|
+
|
16
|
+
say "Copying files for #{template}..."
|
17
|
+
|
18
|
+
manifest.each do |file|
|
19
|
+
copy!(file)
|
11
20
|
end
|
21
|
+
|
12
22
|
say "done!"
|
13
23
|
end
|
14
24
|
|
15
|
-
def
|
16
|
-
|
17
|
-
ask "Are you sure you want to create a new project? ".bold do |answer|
|
18
|
-
answer =~ /^y/i
|
19
|
-
end
|
25
|
+
def manifest
|
26
|
+
File.read(template_path('manifest.txt')).split(/\n+/).reject(&:blank?)
|
20
27
|
end
|
21
28
|
|
22
|
-
def
|
23
|
-
|
29
|
+
def target
|
30
|
+
options.target
|
24
31
|
end
|
25
32
|
|
26
33
|
def project_name
|
27
|
-
|
34
|
+
options.project_name
|
35
|
+
end
|
36
|
+
|
37
|
+
def template
|
38
|
+
options.template
|
28
39
|
end
|
29
40
|
|
30
41
|
def module_name
|
31
|
-
project_name.
|
42
|
+
project_name.split(/\W/).map(&:capitalize).join
|
32
43
|
end
|
33
44
|
|
34
|
-
def
|
35
|
-
File.expand_path
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
path \
|
40
|
-
.gsub('PROJECT', project_name.gsub(/\W+/, '_')) \
|
41
|
-
.sans('.erb')
|
42
|
-
].compact.join("/")
|
45
|
+
def target_path(path='')
|
46
|
+
File.expand_path File.join(
|
47
|
+
Dir.pwd,
|
48
|
+
target,
|
49
|
+
path.gsub('PROJECT', project_name.gsub(/\W+/, '_')))
|
43
50
|
end
|
44
51
|
|
45
|
-
def
|
46
|
-
File.join(File.dirname(__FILE__), *%W[.. .. templates #{path}])
|
52
|
+
def template_path(path='')
|
53
|
+
File.expand_path File.join(File.dirname(__FILE__), *%W[.. .. templates #{template} #{path}])
|
47
54
|
end
|
48
55
|
|
49
56
|
def copy!(path)
|
50
57
|
begin
|
51
58
|
read(path) \
|
52
59
|
.erb_eval(binding) \
|
53
|
-
.write(
|
60
|
+
.write(target_path(path))
|
61
|
+
rescue Errno::ENOENT => e
|
62
|
+
raise e if File.exists?(target_path)
|
63
|
+
FileUtils.mkdir_p(target_path)
|
64
|
+
retry
|
54
65
|
rescue Errno::EISDIR
|
55
|
-
FileUtils.
|
66
|
+
FileUtils.mkdir_p target_path(path)
|
56
67
|
end
|
57
68
|
end
|
58
69
|
|
70
|
+
def performing?
|
71
|
+
@performing
|
72
|
+
end
|
73
|
+
|
59
74
|
def read(path)
|
60
|
-
File.read(
|
75
|
+
File.read(template_path(path))
|
61
76
|
end
|
62
77
|
|
63
78
|
def say(msg)
|
64
|
-
puts(msg)
|
79
|
+
puts(msg) if performing?
|
65
80
|
end
|
66
81
|
|
67
82
|
def ask(msg)
|
68
|
-
print msg
|
83
|
+
print msg if performing?
|
69
84
|
yield $stdin.gets.chomp
|
70
85
|
end
|
71
86
|
end
|
data/lib/another.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[core_ext])
|
2
2
|
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[another])
|
3
3
|
|
4
|
-
%w[rubygems colored fileutils string symbol runner].each { |lib| require lib }
|
4
|
+
%w[rubygems colored fileutils string symbol options confirmer runner].each { |lib| require lib }
|
5
5
|
|
6
6
|
module Another
|
7
7
|
def self.run(args)
|
8
|
-
Runner.new(args)
|
8
|
+
Runner.new(args).perform!
|
9
9
|
end
|
10
10
|
end
|
data/lib/core_ext/string.rb
CHANGED
@@ -6,13 +6,21 @@ class String
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def write(path)
|
9
|
-
|
10
|
-
File.open(path, 'w') do |file|
|
9
|
+
File.open(path, 'w+') do |file|
|
11
10
|
file << self
|
12
11
|
end
|
12
|
+
puts "- #{path}"
|
13
13
|
end
|
14
14
|
|
15
15
|
def sans(str)
|
16
16
|
gsub(str, '')
|
17
17
|
end
|
18
|
+
|
19
|
+
def blank?
|
20
|
+
gsub(/\t|\s/, '').empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def underscore
|
24
|
+
gsub(/\W+/, '_')
|
25
|
+
end
|
18
26
|
end
|
data/spec/another_spec.rb
CHANGED
@@ -2,31 +2,60 @@ require 'spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe Another do
|
4
4
|
it "runs" do
|
5
|
-
mock(
|
5
|
+
mock(runner = Object.new).perform!
|
6
|
+
mock(Another::Runner).new(['one-more']).returns(runner)
|
6
7
|
Another.run(['one-more'])
|
7
8
|
end
|
8
9
|
|
9
10
|
describe Another::Runner do
|
10
11
|
attr_reader :runner
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
describe "basics" do
|
14
|
+
before(:each) do
|
15
|
+
@runner = Another::Runner.new(['one-more'])
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets project_name" do
|
19
|
+
runner.project_name.should == 'one-more'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets module name" do
|
23
|
+
runner.module_name.should == 'OneMore'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "get target_path" do
|
27
|
+
stub(Dir).pwd { '/User/foo' }
|
28
|
+
runner.target_path.should == '/User/foo/one-more'
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
32
|
+
describe "template options" do
|
33
|
+
context "when no option specified" do
|
34
|
+
before(:each) do
|
35
|
+
@runner = Another::Runner.new(['one-more'])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "is ruby" do
|
39
|
+
runner.template.should == 'ruby'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when --sinatra" do
|
44
|
+
before(:each) do
|
45
|
+
@runner = Another::Runner.new(['one-more', '--template', 'sinatra'])
|
46
|
+
end
|
47
|
+
|
48
|
+
it "is ruby" do
|
49
|
+
runner.template.should == 'sinatra'
|
50
|
+
end
|
51
|
+
end
|
27
52
|
end
|
28
53
|
|
29
54
|
describe "confirmation" do
|
55
|
+
before(:each) do
|
56
|
+
@runner = Another::Runner.new(['one-more'])
|
57
|
+
end
|
58
|
+
|
30
59
|
context "when yes" do
|
31
60
|
it "is confirmed" do
|
32
61
|
stub($stdin).gets { "y" }
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: another
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Nakajima
|
@@ -31,29 +31,73 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
33
|
files:
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
34
|
+
- .git
|
35
|
+
- another.gemspec
|
36
|
+
- bin
|
37
|
+
- bin/.
|
38
|
+
- bin/..
|
39
|
+
- bin/another
|
40
|
+
- lib
|
41
|
+
- lib/.
|
42
|
+
- lib/..
|
43
|
+
- lib/another
|
44
|
+
- lib/another/.
|
45
|
+
- lib/another/..
|
46
|
+
- lib/another/confirmer.rb
|
47
|
+
- lib/another/options.rb
|
48
|
+
- lib/another/runner.rb
|
49
|
+
- lib/another.rb
|
50
|
+
- lib/core_ext
|
51
|
+
- lib/core_ext/.
|
52
|
+
- lib/core_ext/..
|
53
|
+
- lib/core_ext/string.rb
|
54
|
+
- lib/core_ext/symbol.rb
|
55
|
+
- README
|
56
|
+
- spec
|
57
|
+
- spec/.
|
58
|
+
- spec/..
|
59
|
+
- spec/another_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
- templates
|
62
|
+
- templates/.
|
63
|
+
- templates/..
|
64
|
+
- templates/ruby
|
65
|
+
- templates/ruby/.
|
66
|
+
- templates/ruby/..
|
67
|
+
- templates/ruby/lib
|
68
|
+
- templates/ruby/lib/.
|
69
|
+
- templates/ruby/lib/..
|
70
|
+
- templates/ruby/lib/PROJECT
|
71
|
+
- templates/ruby/lib/PROJECT/.
|
72
|
+
- templates/ruby/lib/PROJECT/..
|
73
|
+
- templates/ruby/lib/PROJECT/.gitignore
|
74
|
+
- templates/ruby/lib/PROJECT.rb
|
75
|
+
- templates/ruby/manifest.txt
|
76
|
+
- templates/ruby/README.textile
|
77
|
+
- templates/ruby/spec
|
78
|
+
- templates/ruby/spec/.
|
79
|
+
- templates/ruby/spec/..
|
80
|
+
- templates/ruby/spec/PROJECT_spec.rb
|
81
|
+
- templates/ruby/spec/spec_helper.rb
|
82
|
+
- templates/sinatra
|
83
|
+
- templates/sinatra/.
|
84
|
+
- templates/sinatra/..
|
85
|
+
- templates/sinatra/app.rb
|
86
|
+
- templates/sinatra/manifest.txt
|
87
|
+
- templates/sinatra/public
|
88
|
+
- templates/sinatra/public/.
|
89
|
+
- templates/sinatra/public/..
|
90
|
+
- templates/sinatra/public/.gitignore
|
91
|
+
- templates/sinatra/spec
|
92
|
+
- templates/sinatra/spec/.
|
93
|
+
- templates/sinatra/spec/..
|
94
|
+
- templates/sinatra/spec/.gitignore
|
95
|
+
- templates/sinatra/spec/PROJECT_spec.rb
|
96
|
+
- templates/sinatra/spec/spec_helper.rb
|
97
|
+
- templates/sinatra/views
|
98
|
+
- templates/sinatra/views/.
|
99
|
+
- templates/sinatra/views/..
|
100
|
+
- templates/sinatra/views/.gitignore
|
57
101
|
has_rdoc: false
|
58
102
|
homepage:
|
59
103
|
post_install_message:
|