gemmer 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +109 -0
  2. data/src/gemmer.rb +179 -0
  3. metadata +54 -0
data/README.rdoc ADDED
@@ -0,0 +1,109 @@
1
+ = gemmer
2
+
3
+ Author:: Thomas Kadauke - tkadauke (at) imedo.de
4
+ Copyright:: Copyright (c) 2010 Thomas Kadauke
5
+ Licence:: MIT
6
+ Git:: http://github.com/tkadauke/gemmer
7
+
8
+ Simplify rake tasks for Rubygems. It is a little bit like jeweler, but less complicated and it allows you to distribute your gem to your internal servers. In contrast to jeweler, it is really just a way to keep your Rakefile DRY, without taking control over your whole gem.
9
+
10
+ == Dependencies
11
+
12
+ * rubygems
13
+ * active_support
14
+
15
+ == Installation
16
+
17
+ Install from rubygems.org:
18
+
19
+ sudo gem install gemmer
20
+
21
+ Install from source
22
+
23
+ git clone git://github.com/tkadauke/gemmer
24
+ cd gemmer
25
+ sudo rake install
26
+
27
+ == Usage
28
+
29
+ Add the following code to your gem's Rakefile
30
+
31
+ begin
32
+ require 'gemmer'
33
+
34
+ Gemmer::Tasks.new('my_gem')
35
+ rescue LoadError
36
+ puts "Gemmer not available. Install it with: gem install gemmer"
37
+ end
38
+
39
+ replace 'my_gem' with the name of your gem. If you want to release your gem to the public and/or on private internal machines, you can easily define release tasks like so:
40
+
41
+ Gemmer::Tasks.new('my_gem') do |t|
42
+ # to release the gem to rubygems.org
43
+ t.release_via :rubygems
44
+ # to release the gem to a remote machine
45
+ t.release_via :ssh, :to => 'some_host', :username => 'me', :use_sudo => true
46
+ end
47
+
48
+ Gemmer will then define tasks to build your gem, install/uninstall it locally, and in the latter case release them to rubygems.org, and via SSH to host 'some_host'.
49
+
50
+ == Building / Installing
51
+
52
+ Used to its bare minimum, gemmer defines tasks to build and install your gem:
53
+
54
+ rake build
55
+ rake install
56
+ rake uninstall
57
+ rake reinstall
58
+
59
+ Note that the install tasks might require root privileges, so prefix them with sudo:
60
+
61
+ sudo rake install
62
+ sudo rake uninstall
63
+ sudo rake reinstall
64
+
65
+ == Releasing
66
+
67
+ There are several ways to release a gem using gemmer. You can specify multiple release targets. Each will get its own task in the release namespace. To release to every target at once, use
68
+
69
+ rake release
70
+
71
+ === Release on rubygems.org
72
+
73
+ To release on rubygems.org, use gemmer like this in your Rakefile:
74
+
75
+ Gemmer::Tasks.new('my_gem') do |t|
76
+ t.release_via :rubygems
77
+ end
78
+
79
+ Then, gemmer generates the task
80
+
81
+ rake release:rubygems
82
+
83
+ === Release via SSH on a remote machine
84
+
85
+ This is where gemmer really shines. It allows you to release a gem to a remote machine (possibly an internal server), so gemmer is perfectly suitable for handling and distributing your internal or private gems. Use like this in your Rakefile:
86
+
87
+ Gemmer::Tasks.new('my_gem') do |t|
88
+ t.release_via :ssh, :to => 'my_host', :username => 'me', :use_sudo => true
89
+ end
90
+
91
+ And you will get the task
92
+
93
+ rake release:my_host
94
+
95
+ === Release via Scatter to a group of hosts
96
+
97
+ Scatter is a tool to distribute gems on internal and/or production servers. Once configured, you can push any gem to an unlimited number of servers. Scatter uses host names and host groups as targets for your gem. With gemmer, just specify the target name, and you're good to go:
98
+
99
+ Gemmer::Tasks.new('my_gem') do |t|
100
+ t.release_via :scatter, :to => 'my_host_group'
101
+ end
102
+
103
+ Then, release with
104
+
105
+ rake release:my_host_group
106
+
107
+ == TODO
108
+
109
+ - Release to rubyforge
data/src/gemmer.rb ADDED
@@ -0,0 +1,179 @@
1
+ require 'rake/gempackagetask'
2
+ require 'rake/rdoctask'
3
+ require 'active_support'
4
+
5
+ # Deprecated. Don't use.
6
+ def gemmer(gem_name)
7
+ puts "WARNING: the gemmer method is deprecated. Use Gemmer::Tasks.new(gem_name) instead"
8
+
9
+ Gemmer::Tasks.new(gem_name)
10
+ end
11
+
12
+ module Gemmer #:nodoc:
13
+ # Defines a couple of convenient tasks to build, install and release gems.
14
+ #
15
+ # Complete usage example:
16
+ #
17
+ # Gemmer::Tasks.new('my_gem') do |t|
18
+ # t.gemspec_file = 'my_gem.gemspec' # <- this is the default
19
+ # t.gemspec_erb_file = 'my_gem.gemspec.erb' # <- this is the default
20
+ # t.package_path = 'pkg' # <- this is the default
21
+ #
22
+ # t.release_via :rubygems
23
+ # t.release_via :ssh, :to => 'some_host', :username => 'me', :use_sudo => true
24
+ # t.release_via :ssh, :to => 'production', :host => 'some_other_hostname', :username => 'me', :use_sudo => false
25
+ # t.release_via :scatter, :to => 'my_host_group'
26
+ # end
27
+ class Tasks
28
+ attr_accessor_with_default(:gemspec_file) { "#{@gem_name}.gemspec" }
29
+ attr_accessor_with_default(:gemspec_erb_file) { "#{gemspec_file}.erb" }
30
+ attr_accessor_with_default :package_path, "pkg"
31
+
32
+ # contains the Gem::Specification instance
33
+ attr_reader :spec
34
+
35
+ # Define gem tasks. The only argument is the name of the gem. Yields itself to a block
36
+ # if given.
37
+ #
38
+ # The following writer methods are defined on the yielded object:
39
+ #
40
+ # gemspec_file:: relative path to the gemspec file. Defaults to <gem_name>.gemspec
41
+ # gemspec_erb_file:: relative path of an erb template for generating the gemspec file. Use this only if you need to (e.g. Github did not allow Dir.glob in gemspec files, so a workaround was to use an erb file to glob for the files locally and generate the gemspec file from that.)
42
+ # package_path:: relative path under which the built gem is stored. Defaults to pkg
43
+ def initialize(gem_name)
44
+ @gem_name = gem_name
45
+ @release_destinations = {}
46
+ yield self if block_given?
47
+ define
48
+ end
49
+
50
+ # Add another release method. Available release methods are:
51
+ #
52
+ # - rubygems: Release the gem to rubygems.org
53
+ # - ssh: Release the gem to another computer via scp / ssh. Options are:
54
+ # - :to - Symbolic name and/or host name for the target machine. Required.
55
+ # - :host - Host name of the target machine. If not specified, the :to option is used.
56
+ # - :username - SSH user name
57
+ # - :use_sudo - Whether to use sudo for installing the gem on the remote machine.
58
+ # - scatter: Release the gem using scatter. Options are:
59
+ # - :to - Name of target host / group
60
+ def release_via(release_method, options = nil)
61
+ @release_destinations[release_method] = options
62
+ end
63
+
64
+ protected
65
+ def define
66
+ @spec = eval(File.read(gemspec_file))
67
+ @file_name = "#{@gem_name}-#{@spec.version}.gem"
68
+ @package = File.join(package_path, @file_name)
69
+
70
+ define_gem_tasks
71
+ define_install_tasks
72
+ define_release_tasks
73
+ define_rdoc_tasks
74
+ end
75
+
76
+ def define_gem_tasks
77
+ Rake::GemPackageTask.new(@spec) do |pkg|
78
+ pkg.need_tar = true
79
+ end
80
+
81
+ desc "Build gem"
82
+ task :build => @package do
83
+ puts "generated latest version"
84
+ end
85
+
86
+ desc "Generate .gemspec file from .gemspec.erb file"
87
+ task :gemspec do
88
+ require 'erb'
89
+ File.open("#{gemspec_file}", 'w') do |file|
90
+ file.puts ERB.new(File.read("#{gemspec_erb_file}")).result
91
+ end
92
+ end
93
+ end
94
+
95
+ def define_install_tasks
96
+ desc "Install gem locally (use sudo rake install if you need privileges)"
97
+ task :install => @package do
98
+ system "gem install #{@package}"
99
+ end
100
+
101
+ desc "Uninstall gem (use sudo rake uninstall if you need privileges)"
102
+ task :uninstall do
103
+ system "gem uninstall #{@gem_name}"
104
+ end
105
+
106
+ desc "Reinstall gem (use sudo rake reinstall if you need privileges)"
107
+ task :reinstall => [:uninstall, :install]
108
+ end
109
+
110
+ def define_rdoc_tasks
111
+ desc "Generate documentation for #{@gem_name}."
112
+ Rake::RDocTask.new(:rdoc) do |rdoc|
113
+ rdoc.rdoc_dir = 'rdoc'
114
+ rdoc.title = @gem_name
115
+ rdoc.options << '--line-numbers' << '--inline-source'
116
+ rdoc.rdoc_files.include(spec.files.sort)
117
+ end
118
+ end
119
+
120
+ def define_release_tasks
121
+ task_names = @release_destinations.collect do |release_method, options|
122
+ define_release_task(release_method, options)
123
+ end
124
+
125
+ unless task_names.empty?
126
+ desc "Release #{@gem_name} to all destinations"
127
+ task :release => task_names
128
+ end
129
+ end
130
+
131
+ def define_release_task(release_method, options)
132
+ case release_method.to_s.downcase
133
+ when 'rubygems'
134
+ define_rubygems_release_task
135
+ when 'ssh'
136
+ define_ssh_release_task(options)
137
+ when 'scatter'
138
+ define_scatter_release_task(options)
139
+ else
140
+ raise "Unknown release method #{release_method}"
141
+ end
142
+ end
143
+
144
+ def define_rubygems_release_task
145
+ namespace :release do
146
+ desc "Release #{@gem_name} to rubygems.org"
147
+ task :rubygems do
148
+ sh "gem push #{@package}"
149
+ end
150
+ end
151
+
152
+ "release:rubygems"
153
+ end
154
+
155
+ def define_ssh_release_task(options)
156
+ namespace :release do
157
+ desc "Release #{@gem_name} to #{options[:to]} via SSH"
158
+ task options[:to] do
159
+ ssh_string = "#{options[:username]}@#{options[:host] || options[:to]}"
160
+ sh "scp #{@package} #{ssh_string}:/tmp/"
161
+ sh "ssh #{ssh_string} #{options[:use_sudo]} gem install /tmp/#{@file_name}"
162
+ end
163
+ end
164
+
165
+ "release:#{options[:to]}"
166
+ end
167
+
168
+ def define_scatter_release_task(options)
169
+ namespace :release do
170
+ desc "Release #{@gem_name} to #{options[:to]} via scatter"
171
+ task options[:to] do
172
+ sh "scatter push #{@package} #{options[:to]}"
173
+ end
174
+ end
175
+
176
+ "release:#{options[:to]}"
177
+ end
178
+ end
179
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemmer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Kadauke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-04-10 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: tkadauke@imedo.de
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - src/gemmer.rb
26
+ - README.rdoc
27
+ has_rdoc: true
28
+ homepage: http://www.imedo.de/
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - src
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: "0"
39
+ version:
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.3.1
50
+ signing_key:
51
+ specification_version: 2
52
+ summary: Simple rake tasks for gems
53
+ test_files: []
54
+