simple-gem 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,6 +18,12 @@ spec = Gem::Specification.new do |s|
18
18
  s.homepage = 'http://sneaq.net'
19
19
  s.executables = ['simple-gem']
20
20
  s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test,templates}/**/*")
21
+
22
+ s.add_development_dependency('rake', '~> 0.8.0')
23
+ s.add_development_dependency('bundler', '~> 1.0.0')
24
+ s.add_development_dependency('jnunemaker-matchy', '~> 0.4.0')
25
+ s.add_development_dependency('shoulda', '~> 2.11.0')
26
+ s.add_development_dependency('mocha', '~> 0.9.0')
21
27
  end
22
28
 
23
29
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -28,4 +34,11 @@ Rake::TestTask.new do |t|
28
34
  t.libs << 'test'
29
35
  t.test_files = FileList["test/**/*_test.rb"]
30
36
  t.verbose = true
37
+ end
38
+
39
+ desc 'Generate the gemspec for this Gem'
40
+ task :gemspec do
41
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
42
+ File.open(file, 'w') {|f| f << spec.to_ruby }
43
+ puts "Created gemspec: #{file}"
31
44
  end
@@ -4,7 +4,10 @@ require 'simple_gem'
4
4
 
5
5
  if ARGV[0]
6
6
  gem = SimpleGem::Gem.new(`pwd`.strip, ARGV[0])
7
- gem.generate
7
+ gem.generate_structure
8
+ gem.generate_gemspec
9
+
10
+ $stderr.puts "Generated new gem structure for #{gem.name}"
8
11
  else
9
12
  puts "Please specify a name for your gem"
10
13
  end
@@ -1,59 +1,77 @@
1
1
  module SimpleGem
2
2
  class Gem
3
-
4
- attr_reader :root_path, :name
5
-
3
+
4
+ attr_reader :root_path
5
+
6
6
  def initialize(path, name)
7
7
  @root_path = path
8
- self.name = name
8
+ @name = name
9
9
  end
10
-
11
- def name=(name)
12
- @name = name.gsub(/([A-Z])([a-z])/, '_\1\2').sub(/^_/, '').downcase
10
+
11
+ def name
12
+ sanitized_name
13
13
  end
14
-
14
+
15
15
  def module_name
16
16
  transform_name {|part| part.capitalize }
17
17
  end
18
-
18
+
19
19
  def ruby_name
20
20
  transform_name('_') {|part| part.downcase }
21
21
  end
22
22
 
23
- def generate
24
- generate_root_directory
23
+ def generate_structure
24
+ generate_gem_directory
25
25
  generate_subdirectories
26
26
  generate_file('gitignore.erb', '.gitignore')
27
- generate_file('lib.rb.erb', "lib/#{self.ruby_name}.rb")
28
- generate_file('lib_version.rb.erb', "lib/#{self.ruby_name}/version.rb")
27
+ generate_file('rvmrc.erb', '.rvmrc')
28
+ generate_file('lib.rb.erb', "lib/#{ruby_name}.rb")
29
+ generate_file('lib_version.rb.erb', "lib/#{ruby_name}/version.rb")
29
30
  generate_file('Rakefile.erb', 'Rakefile')
31
+ generate_file('Gemfile.erb', 'Gemfile')
30
32
  generate_file('README.rdoc.erb', 'README.rdoc')
31
33
  generate_file('test_helper.rb.erb', 'test/test_helper.rb')
32
- generate_file('test.rb.erb', "test/unit/#{self.ruby_name}_test.rb")
34
+ generate_file('test.rb.erb', "test/unit/#{ruby_name}_test.rb")
33
35
  end
34
-
36
+
37
+ def generate_gemspec
38
+ Dir.chdir(gem_path) { `rake gemspec 2>&1` }
39
+ end
40
+
35
41
  private
42
+
43
+ def sanitized_name
44
+ @name.gsub(/([A-Z])([a-z])/, '_\1\2').sub(/^_/, '').downcase
45
+ end
46
+
36
47
  def transform_name(glue = nil, &block)
37
- self.name.split(/[_-]/).map {|part| block.call(part) }.join(glue)
48
+ name.split(/[_-]/).map {|part| block.call(part) }.join(glue)
38
49
  end
39
-
40
- def generate_root_directory
41
- FileUtils.mkdir("#{self.root_path}/#{self.name}")
50
+
51
+ def generate_gem_directory
52
+ FileUtils.mkdir(gem_path)
42
53
  end
43
-
54
+
44
55
  def generate_subdirectories
45
- ['lib', 'test', "lib/#{self.ruby_name}", 'test/unit'].each do |dir|
46
- FileUtils.mkdir("#{self.root_path}/#{self.name}/#{dir}")
56
+ ['lib', 'test', "lib/#{ruby_name}", 'test/unit'].each do |dir|
57
+ FileUtils.mkdir(path_to(dir))
47
58
  end
48
59
  end
49
-
60
+
50
61
  def generate_file(source, output)
51
- source_file = File.dirname(__FILE__) + "/../../templates/#{source}"
52
- output_file = "#{self.root_path}/#{self.name}/#{output}"
53
-
62
+ source_file = File.expand_path("../../../templates/#{source}", __FILE__)
63
+
54
64
  erb = ERB.new(File.read(source_file))
55
- File.open(output_file, 'w') {|f| f << erb.result(binding) }
65
+ File.open(path_to(output), 'w') {|f| f << erb.result(binding) }
56
66
  end
57
-
67
+
68
+ def gem_path
69
+ "#{root_path}/#{name}"
70
+ end
71
+
72
+ def path_to(target)
73
+ "#{gem_path}/#{target}"
74
+ end
75
+
58
76
  end
59
77
  end
@@ -1,13 +1,13 @@
1
1
  module SimpleGem
2
2
  module Version
3
-
3
+
4
4
  MAJOR = 0
5
- MINOR = 5
6
- TINY = 1
7
-
5
+ MINOR = 6
6
+ TINY = 0
7
+
8
8
  def self.to_s
9
9
  [MAJOR, MINOR, TINY].join('.')
10
10
  end
11
-
11
+
12
12
  end
13
13
  end
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -1,16 +1,16 @@
1
- = <%= self.module_name %>
1
+ = <%= module_name %>
2
2
 
3
3
  == Description
4
4
 
5
- Describe your gem here ...
5
+ Describe your gem here ...
6
6
 
7
7
  == Installation
8
8
 
9
- sudo gem install <%= self.name %>
9
+ gem install <%= name %>
10
10
 
11
11
  == Usage
12
12
 
13
- require '<%= self.ruby_name %>'
13
+ require '<%= ruby_name %>'
14
14
 
15
15
  == License
16
16
 
@@ -2,11 +2,11 @@ require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
  require 'rake/testtask'
4
4
 
5
- require File.join(File.dirname(__FILE__), %w(lib <%= self.ruby_name %> version))
5
+ require File.join(File.dirname(__FILE__), %w(lib <%= ruby_name %> version))
6
6
 
7
7
  spec = Gem::Specification.new do |s|
8
- s.name = '<%= self.name %>'
9
- s.version = <%= self.module_name %>::Version.to_s
8
+ s.name = '<%= name %>'
9
+ s.version = <%= module_name %>::Version.to_s
10
10
  s.has_rdoc = true
11
11
  s.extra_rdoc_files = %w(README.rdoc)
12
12
  s.rdoc_options = %w(--main README.rdoc)
@@ -15,9 +15,15 @@ spec = Gem::Specification.new do |s|
15
15
  s.email = 'user@example.com'
16
16
  s.homepage = 'http://my-site.net'
17
17
  s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
18
- # s.executables = ['<%= self.name %>']
19
-
18
+ # s.executables = ['<%= name %>']
19
+
20
20
  # s.add_dependency('gem_name', '~> 0.0.1')
21
+
22
+ s.add_development_dependency('rake', '~> 0.8.0')
23
+ s.add_development_dependency('bundler', '~> 1.0.0')
24
+ s.add_development_dependency('jnunemaker-matchy', '~> 0.4.0')
25
+ s.add_development_dependency('shoulda', '~> 2.11.0')
26
+ s.add_development_dependency('mocha', '~> 0.9.0')
21
27
  end
22
28
 
23
29
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -44,10 +50,17 @@ begin
44
50
  t.verbose = true
45
51
  t.rcov_opts = options
46
52
  end
47
-
53
+
48
54
  task :default => :coverage
49
-
55
+
50
56
  rescue LoadError
51
57
  warn "\n**** Install rcov (gem install rcov) to get coverage stats ****\n"
52
58
  task :default => :test
59
+ end
60
+
61
+ desc 'Generate the gemspec for this Gem'
62
+ task :gemspec do
63
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
64
+ File.open(file, 'w') {|f| f << spec.to_ruby }
65
+ puts "Created gemspec: #{file}"
53
66
  end
@@ -1,3 +1,4 @@
1
1
  /pkg/
2
2
  /doc/
3
- /coverage/
3
+ /coverage/
4
+ /.bundle
@@ -1,3 +1,3 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
- # require '<%= self.ruby_name %>/...'
3
+ # require '<%= ruby_name %>/...'
@@ -1,13 +1,13 @@
1
- module <%= self.module_name %>
1
+ module <%= module_name %>
2
2
  module Version
3
-
3
+
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
6
  TINY = 0
7
-
7
+
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
10
10
  end
11
-
11
+
12
12
  end
13
13
  end
@@ -0,0 +1 @@
1
+ rvm 1.9.2@<%= name %> --create
@@ -1,13 +1,13 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), %w(.. test_helper)))
2
2
 
3
- class <%= self.module_name %>Test < Test::Unit::TestCase
3
+ class <%= module_name %>Test < Test::Unit::TestCase
4
4
 
5
- context "An instance of the <%= self.module_name %> class" do
5
+ context "An instance of the <%= module_name %> class" do
6
6
 
7
7
  should "flunk" do
8
8
  flunk "Please provide some tests"
9
9
  end
10
-
10
+
11
11
  end
12
12
 
13
13
  end
@@ -5,4 +5,4 @@ require 'rubygems'
5
5
  require 'test/unit'
6
6
  require 'shoulda'
7
7
 
8
- require File.dirname(__FILE__) + '/../lib/<%= self.ruby_name %>'
8
+ require File.dirname(__FILE__) + '/../lib/<%= ruby_name %>'
@@ -27,47 +27,43 @@ module SimpleGem
27
27
  end
28
28
  end
29
29
 
30
- should_generate :name => 'simple_gem',
31
- :module_name => 'SimpleGem',
32
- :ruby_name => 'simple_gem',
30
+ should_generate :name => 'simple_gem',
31
+ :module_name => 'SimpleGem',
32
+ :ruby_name => 'simple_gem',
33
33
  :from => 'SimpleGem'
34
34
 
35
35
 
36
- should_generate :name => 'simple-gem',
37
- :module_name => 'SimpleGem',
38
- :ruby_name => 'simple_gem',
36
+ should_generate :name => 'simple-gem',
37
+ :module_name => 'SimpleGem',
38
+ :ruby_name => 'simple_gem',
39
39
  :from => 'simple-gem'
40
40
 
41
- should_generate :name => 'simple_gem',
42
- :module_name => 'SimpleGem',
43
- :ruby_name => 'simple_gem',
41
+ should_generate :name => 'simple_gem',
42
+ :module_name => 'SimpleGem',
43
+ :ruby_name => 'simple_gem',
44
44
  :from => 'simple_gem'
45
45
 
46
- should_generate :name => 'simple_gem',
47
- :module_name => 'SimpleGem',
48
- :ruby_name => 'simple_gem',
46
+ should_generate :name => 'simple_gem',
47
+ :module_name => 'SimpleGem',
48
+ :ruby_name => 'simple_gem',
49
49
  :from => 'simpleGem'
50
50
 
51
51
  context "An instance of the Gem class" do
52
- setup { @path = '/this/path' }
52
+ setup do
53
+ @tmp_dir = File.expand_path('../../../tmp', __FILE__)
54
+ FileUtils.mkdir(@tmp_dir) unless File.exist?(@tmp_dir)
53
55
 
54
- should " know its root path" do
55
- Gem.new(@path, 'name').root_path.should == @path
56
+ @name = 'simple-gem'
57
+ @gem = Gem.new(@tmp_dir, @name)
56
58
  end
57
59
 
58
- context "when generating the directory structure" do
59
-
60
- setup do
61
- @tmp_dir = File.dirname(__FILE__) + '/../../tmp'
62
- FileUtils.mkdir(@tmp_dir) unless File.exist?(@tmp_dir)
63
-
64
- @name = 'simple-gem'
65
- Gem.new(@tmp_dir, @name).generate
66
- end
60
+ should "know its root path" do
61
+ @gem.root_path.should == @tmp_dir
62
+ end
67
63
 
68
- teardown do
69
- FileUtils.rm_rf(@tmp_dir)
70
- end
64
+ context "when generating the directory structure" do
65
+ setup { @gem.generate_structure }
66
+ teardown { FileUtils.rm_rf(@tmp_dir) }
71
67
 
72
68
  should "be able to make the root directory" do
73
69
  File.exist?("#{@tmp_dir}/#{@name}").should == true
@@ -82,7 +78,7 @@ module SimpleGem
82
78
  should "create the main library file" do
83
79
  File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem.rb").should == true
84
80
  end
85
-
81
+
86
82
  should "create the version file" do
87
83
  File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem/version.rb").should == true
88
84
  end
@@ -95,6 +91,10 @@ module SimpleGem
95
91
  File.exist?("#{@tmp_dir}/#{@name}/README.rdoc").should == true
96
92
  end
97
93
 
94
+ should "create the Gemfile" do
95
+ File.exist?("#{@tmp_dir}/#{@name}/Gemfile").should == true
96
+ end
97
+
98
98
  should "generate the test helper file" do
99
99
  File.exist?("#{@tmp_dir}/#{@name}/test/test_helper.rb").should == true
100
100
  end
@@ -102,11 +102,19 @@ module SimpleGem
102
102
  should "generate the test file" do
103
103
  File.exist?("#{@tmp_dir}/#{@name}/test/unit/simple_gem_test.rb").should == true
104
104
  end
105
-
105
+
106
106
  should "generate the .gitignore file" do
107
107
  File.exist?("#{@tmp_dir}/#{@name}/.gitignore").should == true
108
108
  end
109
109
 
110
+ should "generate the .rvmrc file" do
111
+ File.exist?("#{@tmp_dir}/#{@name}/.rvmrc").should == true
112
+ end
113
+
114
+ should "be able to generate the gemspec" do
115
+ @gem.generate_gemspec
116
+ File.exist?("#{@tmp_dir}/#{@name}/simple-gem.gemspec").should == true
117
+ end
110
118
  end
111
119
 
112
120
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
8
- - 1
9
- version: 0.5.1
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Patrick Reagan
@@ -14,10 +14,84 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-22 00:00:00 -04:00
17
+ date: 2011-03-21 00:00:00 -06:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 8
31
+ - 0
32
+ version: 0.8.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jnunemaker-matchy
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 4
61
+ - 0
62
+ version: 0.4.0
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: shoulda
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 2
75
+ - 11
76
+ - 0
77
+ version: 2.11.0
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: mocha
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ - 9
91
+ - 0
92
+ version: 0.9.0
93
+ type: :development
94
+ version_requirements: *id005
21
95
  description:
22
96
  email: reaganpr@gmail.com
23
97
  executables:
@@ -33,13 +107,16 @@ files:
33
107
  - lib/simple_gem/version.rb
34
108
  - lib/simple_gem.rb
35
109
  - test/simple_gem/gem_test.rb
110
+ - templates/Gemfile.erb
36
111
  - templates/gitignore.erb
37
112
  - templates/lib.rb.erb
38
113
  - templates/lib_version.rb.erb
39
114
  - templates/Rakefile.erb
40
115
  - templates/README.rdoc.erb
116
+ - templates/rvmrc.erb
41
117
  - templates/test.rb.erb
42
118
  - templates/test_helper.rb.erb
119
+ - bin/simple-gem
43
120
  has_rdoc: true
44
121
  homepage: http://sneaq.net
45
122
  licenses: []
@@ -51,6 +128,7 @@ rdoc_options:
51
128
  require_paths:
52
129
  - lib
53
130
  required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
54
132
  requirements:
55
133
  - - ">="
56
134
  - !ruby/object:Gem::Version
@@ -58,6 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
136
  - 0
59
137
  version: "0"
60
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
61
140
  requirements:
62
141
  - - ">="
63
142
  - !ruby/object:Gem::Version
@@ -67,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
146
  requirements: []
68
147
 
69
148
  rubyforge_project:
70
- rubygems_version: 1.3.6
149
+ rubygems_version: 1.3.7
71
150
  signing_key:
72
151
  specification_version: 3
73
152
  summary: Make gems. Simple.