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 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.3"
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["./**/**/**/**"] << File.join(*%w[. templates lib PROJECT .gitignore])
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
@@ -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
- @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)
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 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
25
+ def manifest
26
+ File.read(template_path('manifest.txt')).split(/\n+/).reject(&:blank?)
20
27
  end
21
28
 
22
- def test_mode?
23
- defined?(Spec)
29
+ def target
30
+ options.target
24
31
  end
25
32
 
26
33
  def project_name
27
- @args.first
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.gsub(/\W+/, '_').split('_').map(&:capitalize).join
42
+ project_name.split(/\W/).map(&:capitalize).join
32
43
  end
33
44
 
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("/")
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 template_directory(path='')
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(target_directory(path))
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.mkdir target_directory(path)
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(template_directory(path))
75
+ File.read(template_path(path))
61
76
  end
62
77
 
63
78
  def say(msg)
64
- puts(msg) unless test_mode?
79
+ puts(msg) if performing?
65
80
  end
66
81
 
67
82
  def ask(msg)
68
- print msg unless test_mode?
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
@@ -6,13 +6,21 @@ class String
6
6
  end
7
7
 
8
8
  def write(path)
9
- puts "- #{path}"
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(Another::Runner).new(['one-more'])
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
- 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'
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
- it "get target_directory" do
25
- stub(Dir).pwd { '/User/foo' }
26
- runner.target_directory.should == '/User/foo/one-more'
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
@@ -0,0 +1,8 @@
1
+ ./lib
2
+ ./lib/PROJECT
3
+ ./lib/PROJECT/.gitignore
4
+ ./lib/PROJECT.rb
5
+ ./README.textile
6
+ ./spec
7
+ ./spec/PROJECT_spec.rb
8
+ ./spec/spec_helper.rb
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+
4
+ get '/' do
5
+ "Hello!"
6
+ end
@@ -0,0 +1,9 @@
1
+ ./app.rb
2
+ ./public
3
+ ./public/.gitignore
4
+ ./spec
5
+ ./spec/PROJECT_spec.rb
6
+ ./spec/spec_helper.rb
7
+ ./spec/.gitignore
8
+ ./views
9
+ ./views/.gitignore
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe 'the app' do
4
+ include Elementor
5
+
6
+ attr_reader :response, :page, :first
7
+
8
+ it "should not blow up" do
9
+ get_it '/'
10
+ response.should be_ok
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ ARGV.clear
2
+
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'sinatra'
6
+ require 'sinatra/test/rspec'
7
+
8
+ require File.join(File.dirname(__FILE__), *%w[.. app])
9
+
10
+ # For view tests
11
+ require 'elementor'
12
+ require 'elementor/spec'
13
+
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.3
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
- - ./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
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: