sr-mg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/mg.rb +79 -0
  2. data/test/mg_test.rb +26 -0
  3. metadata +63 -0
@@ -0,0 +1,79 @@
1
+ require "rake"
2
+ require "rake/clean"
3
+ require "rake/tasklib"
4
+
5
+ class MG < Rake::TaskLib
6
+ attr_accessor :gemspec
7
+
8
+ def initialize(gemspec)
9
+ @gemspec = gemspec
10
+
11
+ define_tasks
12
+ end
13
+
14
+ private
15
+ # Load the gemspec using the same limitations as github
16
+ def spec
17
+ @spec ||= begin
18
+ require "rubygems/specification"
19
+ data = File.read(gemspec)
20
+ spec = nil
21
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
22
+ spec
23
+ end
24
+ end
25
+
26
+ def name
27
+ spec.name
28
+ end
29
+
30
+ def package(ext="")
31
+ "dist/#{spec.name}-#{spec.version}" + ext
32
+ end
33
+
34
+ def define_tasks
35
+ directory "dist/"
36
+ CLOBBER.include("dist")
37
+
38
+ desc "Build and install as local gem"
39
+ task :install => package(".gem") do
40
+ sh "gem install #{package(".gem")}"
41
+ end
42
+
43
+ desc "Publish the current release on Rubyforge"
44
+ task :rubyforge => ["rubyforge:gem", "rubyforge:tarball", "rubyforge:git"]
45
+
46
+ namespace :rubyforge do
47
+ desc "Publish gem and tarball to rubyforge"
48
+ task :gem => package(".gem") do
49
+ sh "rubyforge add_release #{name} #{name} #{spec.version} #{package('.gem')}"
50
+ end
51
+
52
+ task :tarball => package(".tar.gz") do
53
+ sh "rubyforge add_file #{name} #{name} #{spec.version} #{package('.tar.gz')}"
54
+ end
55
+
56
+ desc "Push to gitosis@rubyforge.org:#{name}.git"
57
+ task :git do
58
+ sh "git push gitosis@rubyforge.org:#{name}.git master"
59
+ end
60
+ end
61
+
62
+ desc "Build gem tarball into dist/"
63
+ task :package => %w(.gem .tar.gz).map { |ext| package(ext) }
64
+
65
+ file package(".tar.gz") => "dist/" do |f|
66
+ sh <<-SH
67
+ git archive \
68
+ --prefix=#{name}-#{spec.version}/ \
69
+ --format=tar \
70
+ HEAD | gzip > #{f.name}
71
+ SH
72
+ end
73
+
74
+ file package(".gem") => "dist/" do |f|
75
+ sh "gem build #{name}.gemspec"
76
+ mv File.basename(f.name), f.name
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,26 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../lib/mg"
3
+
4
+ class MGTest < Test::Unit::TestCase
5
+ include Rake
6
+
7
+ def setup
8
+ @mg = MG.new(File.dirname(__FILE__) + "/../mg.gemspec")
9
+ end
10
+
11
+ def test_tasks
12
+ assert_task_defined :install
13
+ assert_task_defined :rubyforge
14
+ assert_task_defined :package
15
+ assert_task_defined "dist/mg-0.0.1.gem"
16
+ assert_task_defined "dist/mg-0.0.1.tar.gz"
17
+
18
+ assert_equal ["rubyforge:gem", "rubyforge:tarball", "rubyforge:git"],
19
+ Task["rubyforge"].prerequisites
20
+ end
21
+
22
+ private
23
+ def assert_task_defined(task_name)
24
+ assert Task.task_defined?(task_name)
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sr-mg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Rozet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
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: simon@rozet.name
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/mg.rb
35
+ - test/mg_test.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/sr/mg
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Minimalistic Gem
62
+ test_files:
63
+ - test/mg_test.rb