gem-this 0.1.5 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ spec = Gem::Specification.new do |s|
15
15
 
16
16
  # Change these as appropriate
17
17
  s.name = "gem-this"
18
- s.version = "0.1.5"
18
+ s.version = "0.2.1"
19
19
  s.summary = "Make existing code into a gem, without any fuss."
20
20
  s.author = "James Adam"
21
21
  s.email = "james@lazyatom.com"
@@ -26,9 +26,9 @@ spec = Gem::Specification.new do |s|
26
26
  # s.rdoc_options = %w(--main Readme.markdown)
27
27
 
28
28
  # Add any extra files to include in the gem
29
- s.files = %w(Rakefile Readme.markdown Rakefile.erb) + Dir.glob("{bin}/**/*")
29
+ s.files = %w(Rakefile Readme.markdown Rakefile.erb) + Dir.glob("{bin,lib}/**/*")
30
30
  s.executables = FileList["bin/**"].map { |f| File.basename(f) }
31
- s.require_paths = ["bin"]
31
+ s.require_paths = ["bin", "lib"]
32
32
 
33
33
  # If you want to depend on other gems, add them here, along with any
34
34
  # relevant versions
@@ -40,6 +40,8 @@ spec = Gem::Specification.new do |s|
40
40
  # If you want to publish automatically to rubyforge, you'll may need
41
41
  # to tweak this, and the publishing task below too.
42
42
  s.rubyforge_project = "gem-this"
43
+
44
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3")
43
45
  end
44
46
 
45
47
  # This task actually builds the gem. We also regenerate a static
@@ -107,4 +109,4 @@ begin
107
109
  end
108
110
  rescue LoadError
109
111
  puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
110
- end
112
+ end
@@ -34,12 +34,12 @@ end
34
34
  spec = Gem::Specification.new do |s|
35
35
 
36
36
  # Change these as appropriate
37
- s.name = "<%= gem_name %>"
37
+ s.name = "<%= name %>"
38
38
  s.version = "0.1.0"
39
39
  s.summary = "What this thing does"
40
- s.author = "Your name"
41
- s.email = "you@example.com"
42
- s.homepage = "http://example.com"
40
+ s.author = "<%= author_name %>"
41
+ s.email = "<%= author_email %>"
42
+ s.homepage = "<%= author_url %>"
43
43
 
44
44
  s.has_rdoc = true
45
45
  <% if readme %>
@@ -74,7 +74,7 @@ spec = Gem::Specification.new do |s|
74
74
 
75
75
  # If you want to publish automatically to rubyforge, you'll may need
76
76
  # to tweak this, and the publishing task below too.
77
- s.rubyforge_project = "<%= gem_name %>"
77
+ s.rubyforge_project = "<%= name %>"
78
78
  end
79
79
 
80
80
  # This task actually builds the gem. We also regenerate a static
@@ -133,7 +133,7 @@ begin
133
133
  )
134
134
 
135
135
  host = "#{config['username']}@rubyforge.org"
136
- remote_dir = "/var/www/gforge-projects/<%= gem_name %>/" # Should be the same as the rubyforge project name
136
+ remote_dir = "/var/www/gforge-projects/<%= name %>/" # Should be the same as the rubyforge project name
137
137
  local_dir = 'rdoc'
138
138
 
139
139
  Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
@@ -24,6 +24,10 @@ The `gem-this` command expects to be run in the directory of your existing code:
24
24
  $ mate lib/sweet_code.rb
25
25
  ... hacking ...
26
26
  $ gem-this
27
+
28
+ New in 0.2.0: we also register a gem command, so you can just type:
29
+
30
+ $ gem this
27
31
 
28
32
  When you run `gem-this`, it will create a new `Rakefile` in your project directory. If you already had a `Rakefile`, it will append to the end of it, so your existing tasks are safe.
29
33
 
@@ -1,72 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'gem_this'
4
+
3
5
  args = ARGV.dup
4
6
 
5
7
  if args.first =~ /-?-h/
6
- puts "Creates a Rakefile suitable for turning the current project into a gem."
8
+ puts GemThis::SUMMARY
7
9
  puts "Usage: #{__FILE__} [-d -h] [gem name]"
8
10
  puts "If a gem name is not given, the name of the current directory will be used as the gem"
9
11
  puts "-h help, prints out this message."
10
- puts "-d debug, only prints out the generated Rakefile."
11
- exit(0)
12
+ puts "-d #{GemThis::DEBUG_MESSAGE}"
13
+ exit
12
14
  end
13
15
 
14
16
  debug = args.delete("-d")
15
17
 
16
- gem_name = args.first || File.basename(Dir.pwd)
17
-
18
- def using_rspec?
19
- File.directory?('spec')
20
- end
21
-
22
- def using_test_unit?
23
- File.directory?('test')
24
- end
25
-
26
- def has_executables?
27
- File.directory?('bin')
28
- end
29
-
30
- def dirs_to_include
31
- %w(bin test spec lib).select { |d| File.directory?(d) }.join(",")
32
- end
33
-
34
- def readme
35
- Dir['*'].find { |f| f =~ /readme/i }
36
- end
37
-
38
- def files_in_root
39
- Dir['*'].reject { |f| File.directory?(f) }.join(" ")
40
- end
41
-
42
- def using_git?
43
- File.exist?(".git")
44
- end
45
-
46
- def add_to_gitignore
47
- return unless File.exist?(".gitignore")
48
- ignores = File.readlines(".gitignore")
49
- ignores += ["pkg", "rdoc"]
50
- File.open(".gitignore", "w") { |f| f.write ignores.map { |l| l.strip }.uniq.join("\n") }
51
- end
52
-
53
- require 'erb'
54
-
55
- template = ERB.new File.read(File.join(File.dirname(__FILE__), '..', 'Rakefile.erb')), nil, '<>'
56
- rakefile = template.result(binding)
57
-
58
- if debug
59
- puts rakefile
60
- exit(0)
61
- else
62
- if File.exist?('Rakefile')
63
- puts "Appended to existing Rakefile"
64
- File.open('Rakefile', 'a') { |f| 2.times { f.puts }; f.write rakefile }
65
- else
66
- puts "Writing new Rakefile"
67
- File.open('Rakefile', 'w') { |f| f.write rakefile }
68
- end
69
- add_to_gitignore if using_git?
70
- end
18
+ GemThis.new(args.first || File.basename(Dir.pwd), debug).create_rakefile
71
19
 
72
- exit(0)
20
+ exit
@@ -0,0 +1,81 @@
1
+ require 'erb'
2
+ require 'etc'
3
+
4
+ class GemThis
5
+ SUMMARY = "Creates a Rakefile suitable for turning the current project into a gem."
6
+ DEBUG_MESSAGE = "debug, only prints out the generated Rakefile."
7
+
8
+ attr_reader :name, :debug
9
+
10
+ def initialize(name, debug)
11
+ @name = name
12
+ @debug = debug
13
+ end
14
+
15
+ def create_rakefile
16
+ template = ERB.new File.read(File.join(File.dirname(__FILE__), '..', 'Rakefile.erb')), nil, '<>'
17
+ rakefile = template.result(binding)
18
+
19
+ if debug
20
+ puts rakefile
21
+ else
22
+ if File.exist?('Rakefile')
23
+ puts "Appended to existing Rakefile"
24
+ File.open('Rakefile', 'a') { |f| 2.times { f.puts }; f.write rakefile }
25
+ else
26
+ puts "Writing new Rakefile"
27
+ File.open('Rakefile', 'w') { |f| f.write rakefile }
28
+ end
29
+ add_to_gitignore if using_git?
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def author_name
36
+ Etc.getpwnam(ENV['USER']).gecos rescue ENV['USER'] # for Windows
37
+ end
38
+
39
+ def author_email
40
+ "youremail@example.com"
41
+ end
42
+
43
+ def author_url
44
+ "http://yoursite.example.com"
45
+ end
46
+
47
+ def using_rspec?
48
+ File.directory?('spec')
49
+ end
50
+
51
+ def using_test_unit?
52
+ File.directory?('test')
53
+ end
54
+
55
+ def has_executables?
56
+ File.directory?('bin')
57
+ end
58
+
59
+ def dirs_to_include
60
+ %w(bin test spec lib).select { |d| File.directory?(d) }.join(",")
61
+ end
62
+
63
+ def readme
64
+ Dir['*'].find { |f| f =~ /readme/i }
65
+ end
66
+
67
+ def files_in_root
68
+ Dir['*'].reject { |f| File.directory?(f) }.join(" ")
69
+ end
70
+
71
+ def using_git?
72
+ File.exist?(".git")
73
+ end
74
+
75
+ def add_to_gitignore
76
+ return unless File.exist?(".gitignore")
77
+ ignores = File.readlines(".gitignore")
78
+ ignores += ["pkg", "rdoc"]
79
+ File.open(".gitignore", "w") { |f| f.write ignores.map { |l| l.strip }.uniq.join("\n") }
80
+ end
81
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems/command_manager'
2
+ require 'rubygems/command'
3
+ require 'gem_this'
4
+
5
+ class Gem::Commands::ThisCommand < Gem::Command
6
+ def initialize
7
+ super 'this', GemThis::SUMMARY, :debug => false
8
+ add_option('-d', '--debug', GemThis::DEBUG_MESSAGE) do |debug, options|
9
+ options[:debug] = debug
10
+ end
11
+ end
12
+
13
+ def summary
14
+ GemThis::SUMMARY
15
+ end
16
+
17
+ def execute
18
+ GemThis.new(options[:args].first || File.basename(Dir.pwd), options[:debug]).create_rakefile
19
+ end
20
+ end
21
+
22
+ Gem::CommandManager.instance.register_command :this
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-this
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Adam
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-08 00:00:00 +01:00
12
+ date: 2009-07-23 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,13 +26,18 @@ files:
26
26
  - Readme.markdown
27
27
  - Rakefile.erb
28
28
  - bin/gem-this
29
+ - lib/gem_this.rb
30
+ - lib/rubygems_plugin.rb
29
31
  has_rdoc: true
30
32
  homepage: http://github.com/lazyatom/gem-this
33
+ licenses: []
34
+
31
35
  post_install_message:
32
36
  rdoc_options: []
33
37
 
34
38
  require_paths:
35
39
  - bin
40
+ - lib
36
41
  required_ruby_version: !ruby/object:Gem::Requirement
37
42
  requirements:
38
43
  - - ">="
@@ -43,14 +48,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
48
  requirements:
44
49
  - - ">="
45
50
  - !ruby/object:Gem::Version
46
- version: "0"
51
+ version: "1.3"
47
52
  version:
48
53
  requirements: []
49
54
 
50
55
  rubyforge_project: gem-this
51
- rubygems_version: 1.3.1
56
+ rubygems_version: 1.3.3
52
57
  signing_key:
53
- specification_version: 2
58
+ specification_version: 3
54
59
  summary: Make existing code into a gem, without any fuss.
55
60
  test_files: []
56
61