another 0.0.3
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/README +18 -0
- data/another.gemspec +31 -0
- data/bin/another +5 -0
- data/lib/another.rb +10 -0
- data/lib/another/runner.rb +72 -0
- data/lib/core_ext/string.rb +18 -0
- data/lib/core_ext/symbol.rb +7 -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 +84 -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/another.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{another}
|
5
|
+
s.version = "0.0.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Pat Nakajima"]
|
9
|
+
s.date = %q{2008-11-20}
|
10
|
+
s.default_executable = %q{another}
|
11
|
+
s.email = %q{patnakajima@gmail.com}
|
12
|
+
s.executables = ["another"]
|
13
|
+
s.files = Dir["./**/**/**/**"] << File.join(*%w[. templates lib PROJECT .gitignore])
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.rubygems_version = %q{1.3.0}
|
16
|
+
s.summary = %q{My new Ruby project generator}
|
17
|
+
|
18
|
+
if s.respond_to? :specification_version then
|
19
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
20
|
+
s.specification_version = 2
|
21
|
+
|
22
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
23
|
+
s.add_runtime_dependency(%q<colored>, [">= 0"])
|
24
|
+
else
|
25
|
+
s.add_dependency(%q<colored>, [">= 0"])
|
26
|
+
end
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<colored>, [">= 0"])
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/bin/another
ADDED
data/lib/another.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[core_ext])
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[another])
|
3
|
+
|
4
|
+
%w[rubygems colored fileutils string symbol runner].each { |lib| require lib }
|
5
|
+
|
6
|
+
module Another
|
7
|
+
def self.run(args)
|
8
|
+
Runner.new(args)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Another
|
2
|
+
class Runner
|
3
|
+
def initialize(args)
|
4
|
+
@args = args
|
5
|
+
return if test_mode?
|
6
|
+
return puts("Probably for the best.") unless confirmed?
|
7
|
+
say "Copying files..."
|
8
|
+
FileUtils.mkdir target_directory
|
9
|
+
Dir[File.join(template_directory, "**", "**")].each do |file|
|
10
|
+
copy!(file.split('/templates/').last)
|
11
|
+
end
|
12
|
+
say "done!"
|
13
|
+
end
|
14
|
+
|
15
|
+
def confirmed?
|
16
|
+
say "Warning: Creating new projects makes you vulnerable to mockery.".bold
|
17
|
+
ask "Are you sure you want to create a new project? ".bold do |answer|
|
18
|
+
answer =~ /^y/i
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_mode?
|
23
|
+
defined?(Spec)
|
24
|
+
end
|
25
|
+
|
26
|
+
def project_name
|
27
|
+
@args.first
|
28
|
+
end
|
29
|
+
|
30
|
+
def module_name
|
31
|
+
project_name.gsub(/\W+/, '_').split('_').map(&:capitalize).join
|
32
|
+
end
|
33
|
+
|
34
|
+
def target_directory(path='')
|
35
|
+
File.expand_path \
|
36
|
+
[
|
37
|
+
Dir.pwd,
|
38
|
+
project_name,
|
39
|
+
path \
|
40
|
+
.gsub('PROJECT', project_name.gsub(/\W+/, '_')) \
|
41
|
+
.sans('.erb')
|
42
|
+
].compact.join("/")
|
43
|
+
end
|
44
|
+
|
45
|
+
def template_directory(path='')
|
46
|
+
File.join(File.dirname(__FILE__), *%W[.. .. templates #{path}])
|
47
|
+
end
|
48
|
+
|
49
|
+
def copy!(path)
|
50
|
+
begin
|
51
|
+
read(path) \
|
52
|
+
.erb_eval(binding) \
|
53
|
+
.write(target_directory(path))
|
54
|
+
rescue Errno::EISDIR
|
55
|
+
FileUtils.mkdir target_directory(path)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def read(path)
|
60
|
+
File.read(template_directory(path))
|
61
|
+
end
|
62
|
+
|
63
|
+
def say(msg)
|
64
|
+
puts(msg) unless test_mode?
|
65
|
+
end
|
66
|
+
|
67
|
+
def ask(msg)
|
68
|
+
print msg unless test_mode?
|
69
|
+
yield $stdin.gets.chomp
|
70
|
+
end
|
71
|
+
end
|
72
|
+
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,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: another
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
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 -05:00
|
13
|
+
default_executable: another
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: colored
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: patnakajima@gmail.com
|
27
|
+
executables:
|
28
|
+
- another
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- ./another.gemspec
|
35
|
+
- ./bin
|
36
|
+
- ./bin/another
|
37
|
+
- ./lib
|
38
|
+
- ./lib/another
|
39
|
+
- ./lib/another/runner.rb
|
40
|
+
- ./lib/another.rb
|
41
|
+
- ./lib/core_ext
|
42
|
+
- ./lib/core_ext/string.rb
|
43
|
+
- ./lib/core_ext/symbol.rb
|
44
|
+
- ./README
|
45
|
+
- ./spec
|
46
|
+
- ./spec/another_spec.rb
|
47
|
+
- ./spec/spec_helper.rb
|
48
|
+
- ./templates
|
49
|
+
- ./templates/lib
|
50
|
+
- ./templates/lib/PROJECT
|
51
|
+
- ./templates/lib/PROJECT.rb.erb
|
52
|
+
- ./templates/README.textile
|
53
|
+
- ./templates/spec
|
54
|
+
- ./templates/spec/PROJECT_spec.rb.erb
|
55
|
+
- ./templates/spec/spec_helper.rb.erb
|
56
|
+
- ./templates/lib/PROJECT/.gitignore
|
57
|
+
has_rdoc: false
|
58
|
+
homepage:
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 2
|
82
|
+
summary: My new Ruby project generator
|
83
|
+
test_files: []
|
84
|
+
|