nakajima-another 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +18 -0
- data/bin/another +5 -0
- data/lib/another.rb +99 -0
- data/spec/another_spec.rb +52 -0
- data/spec/spec_helper.rb +8 -0
- data/templates/README.textile +3 -0
- data/templates/lib/PROJECT.rb.erb +6 -0
- data/templates/lib/PROJECT/.gitignore +0 -0
- data/templates/spec/PROJECT_spec.rb.erb +9 -0
- data/templates/spec/spec_helper.rb.erb +7 -0
- metadata +62 -0
data/README
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= Another =
|
2
|
+
|
3
|
+
My new Ruby project generator.
|
4
|
+
|
5
|
+
== Usage ==
|
6
|
+
|
7
|
+
First install:
|
8
|
+
|
9
|
+
$ gem install nakajima-another
|
10
|
+
|
11
|
+
Then use:
|
12
|
+
|
13
|
+
$ another some-project
|
14
|
+
|
15
|
+
A directory named "some-project" will then be generated with some
|
16
|
+
base project files.
|
17
|
+
|
18
|
+
(c) Copyright 2008 Pat Nakajima, released under the MIT License.
|
data/bin/another
ADDED
data/lib/another.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nakajima'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'activesupport'
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
class String
|
8
|
+
def erb_eval(b)
|
9
|
+
ERB.new(self).result(b)
|
10
|
+
end
|
11
|
+
|
12
|
+
def write(path)
|
13
|
+
puts "- #{path}"
|
14
|
+
File.open(path, 'w') do |file|
|
15
|
+
file << self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def sans(str)
|
20
|
+
self.gsub(str, '')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Another
|
25
|
+
class Runner
|
26
|
+
def initialize(args)
|
27
|
+
@args = args
|
28
|
+
return if test_mode?
|
29
|
+
return puts("Probably for the best.") unless confirmed?
|
30
|
+
say "Copying files..."
|
31
|
+
FileUtils.mkdir target_directory
|
32
|
+
Dir[File.join(template_directory, "**", "**")].each do |file|
|
33
|
+
copy!(file.split('/templates/').last)
|
34
|
+
end
|
35
|
+
say "done!"
|
36
|
+
end
|
37
|
+
|
38
|
+
def confirmed?
|
39
|
+
say "Warning: Creating new projects makes you vulnerable to mockery.".bold
|
40
|
+
ask "Are you sure you want to create a new project? ".bold do |answer|
|
41
|
+
answer =~ /^y/i
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_mode?
|
46
|
+
defined?(Spec)
|
47
|
+
end
|
48
|
+
|
49
|
+
def project_name
|
50
|
+
@args.first
|
51
|
+
end
|
52
|
+
|
53
|
+
def module_name
|
54
|
+
project_name.underscore.camelize
|
55
|
+
end
|
56
|
+
|
57
|
+
def target_directory(path='')
|
58
|
+
File.expand_path \
|
59
|
+
[
|
60
|
+
Dir.pwd,
|
61
|
+
project_name,
|
62
|
+
path \
|
63
|
+
.gsub('PROJECT', project_name.underscore) \
|
64
|
+
.sans('.erb')
|
65
|
+
].compact.join("/")
|
66
|
+
end
|
67
|
+
|
68
|
+
def template_directory(path='')
|
69
|
+
File.expand_path(File.dirname(__FILE__) + '/../templates/' + path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def copy!(path)
|
73
|
+
begin
|
74
|
+
read(path) \
|
75
|
+
.erb_eval(binding) \
|
76
|
+
.write(target_directory(path))
|
77
|
+
rescue Errno::EISDIR
|
78
|
+
FileUtils.mkdir target_directory(path)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def read(path)
|
83
|
+
File.read(template_directory(path))
|
84
|
+
end
|
85
|
+
|
86
|
+
def say(msg)
|
87
|
+
puts(msg) unless test_mode?
|
88
|
+
end
|
89
|
+
|
90
|
+
def ask(msg)
|
91
|
+
print msg unless test_mode?
|
92
|
+
yield $stdin.gets.chomp
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.run(args)
|
97
|
+
Runner.new(args)
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Another do
|
4
|
+
it "runs" do
|
5
|
+
mock(Another::Runner).new(['one-more'])
|
6
|
+
Another.run(['one-more'])
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Another::Runner do
|
10
|
+
attr_reader :runner
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@runner = Another::Runner.new(['one-more'])
|
14
|
+
end
|
15
|
+
|
16
|
+
it "gets project_name" do
|
17
|
+
runner.project_name.should == 'one-more'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "gets module name" do
|
21
|
+
runner.module_name.should == 'OneMore'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "get target_directory" do
|
25
|
+
stub(Dir).pwd { '/User/foo' }
|
26
|
+
runner.target_directory.should == '/User/foo/one-more'
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "confirmation" do
|
30
|
+
context "when yes" do
|
31
|
+
it "is confirmed" do
|
32
|
+
stub($stdin).gets { "y" }
|
33
|
+
runner.should be_confirmed
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when no" do
|
38
|
+
it "is not confirmed" do
|
39
|
+
stub($stdin).gets { "n" }
|
40
|
+
runner.should_not be_confirmed
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when blank" do
|
45
|
+
it "it is not confirmed" do
|
46
|
+
stub($stdin).gets { '' }
|
47
|
+
runner.should_not be_confirmed
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nakajima-another
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat Nakajima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-20 00:00:00 -08:00
|
13
|
+
default_executable: another
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: patnakajima@gmail.com
|
18
|
+
executables:
|
19
|
+
- another
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- bin/another
|
27
|
+
- lib/another.rb
|
28
|
+
- spec/another_spec.rb
|
29
|
+
- spec/spec_helper.rb
|
30
|
+
- templates/README.textile
|
31
|
+
- templates/lib/PROJECT.rb.erb
|
32
|
+
- templates/lib/PROJECT/.gitignore
|
33
|
+
- templates/spec/PROJECT_spec.rb.erb
|
34
|
+
- templates/spec/spec_helper.rb.erb
|
35
|
+
has_rdoc: false
|
36
|
+
homepage:
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: My new Ruby project generator
|
61
|
+
test_files: []
|
62
|
+
|