capgem 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/capgem.rb +33 -0
- data/lib/capgem/gembuilder.rb +64 -0
- data/lib/capgem/servers/mongrel.rb +34 -0
- data/lib/capgem/utils.rb +13 -0
- metadata +50 -0
data/lib/capgem.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'capgem/gembuilder'
|
2
|
+
require 'capgem/utils'
|
3
|
+
|
4
|
+
# =======================================================================
|
5
|
+
# Extension to Capistrano which builds your Rails application to a Gem.
|
6
|
+
# =======================================================================
|
7
|
+
|
8
|
+
Capistrano.configuration(:must_exist).load do
|
9
|
+
desc "A task for packaging your Rails app as a Gem"
|
10
|
+
task :pack do
|
11
|
+
Capgem::Utils.create_directories
|
12
|
+
|
13
|
+
server_name = (server_name || :mongrel).to_s
|
14
|
+
server_class = server_name.capitalize
|
15
|
+
|
16
|
+
begin
|
17
|
+
require "capgem/servers/#{server_name}"
|
18
|
+
server = Capgem::Servers.const_get(server_name.capitalize).new(application)
|
19
|
+
#server = Servers::Mongrel.new(application)
|
20
|
+
server.create_runscripts
|
21
|
+
rescue
|
22
|
+
puts "Unable to create runscripts"
|
23
|
+
end
|
24
|
+
|
25
|
+
gem_builder = Capgem::GemBuilder.new(application, server)
|
26
|
+
gem_builder.author = author if respond_to?(:author)
|
27
|
+
gem_builder.email = email if respond_to?(:email)
|
28
|
+
gem_builder.summary = summary if respond_to?(:summary)
|
29
|
+
gem_builder.description = description if respond_to?(:description)
|
30
|
+
|
31
|
+
gem_builder.build
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
module Capgem
|
5
|
+
class GemBuilder # The GemBuilder handles the construction of the Gem from the Rails app
|
6
|
+
|
7
|
+
# The application name
|
8
|
+
attr_accessor :application
|
9
|
+
|
10
|
+
# The optional application version number (format x.x.x)
|
11
|
+
attr_accessor :version
|
12
|
+
|
13
|
+
# Name of the Gem author
|
14
|
+
attr_accessor :author
|
15
|
+
|
16
|
+
# Email of the Gem author
|
17
|
+
attr_accessor :email
|
18
|
+
|
19
|
+
# Summary of the Gem
|
20
|
+
attr_accessor :summary
|
21
|
+
|
22
|
+
# Description of the Gem
|
23
|
+
attr_accessor :description
|
24
|
+
|
25
|
+
# Initialize the GemBuilder
|
26
|
+
# +application: The application name
|
27
|
+
# version:
|
28
|
+
def initialize(application, server, version=nil)
|
29
|
+
@application = application
|
30
|
+
@server = server
|
31
|
+
@version = version
|
32
|
+
end
|
33
|
+
|
34
|
+
# Return the version used for the Gem. If the version attribute is set then this
|
35
|
+
# method will return that value, otherwise it will return the current SCM version
|
36
|
+
def version
|
37
|
+
return @version || '0.1'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Build the gem
|
41
|
+
def build
|
42
|
+
Gem::manage_gems
|
43
|
+
spec = Gem::Specification.new do |s|
|
44
|
+
s.platform = Gem::Platform::RUBY
|
45
|
+
s.name = @application
|
46
|
+
s.version = version
|
47
|
+
s.author = @author || 'Your Name Here'
|
48
|
+
s.email = @email || 'your.email@your.company'
|
49
|
+
s.summary = @summary || ''
|
50
|
+
s.files = FileList['app/**/*','bin/*','components/**/*','config/**/*','db/**/*',
|
51
|
+
'lib/**/*','log/README','public/**/*','Rakefile','script/**/*','test/**/*','vendor/**/*'].to_a
|
52
|
+
s.executables << "start-#{@application}"
|
53
|
+
s.executables << "stop-#{@application}"
|
54
|
+
@server.dependencies.each do |name, version|
|
55
|
+
s.add_dependency(name, version)
|
56
|
+
s.requirements << "#{name} version #{version}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Build the Gem
|
61
|
+
Gem::Builder::new(spec).build
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Capgem
|
2
|
+
module Servers
|
3
|
+
class Mongrel
|
4
|
+
# Initialize the Mongrel supporter
|
5
|
+
# +application: The name of the application
|
6
|
+
def initialize(application)
|
7
|
+
@application = application
|
8
|
+
end
|
9
|
+
|
10
|
+
# Create the runscripts for starting and stopping Mongrel
|
11
|
+
def create_runscripts
|
12
|
+
posix_runscripts
|
13
|
+
end
|
14
|
+
|
15
|
+
def dependencies
|
16
|
+
{'mongrel', '>=0.0.0'}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
# Create the POSIX runscripts
|
21
|
+
def posix_runscripts
|
22
|
+
puts "Building posix runscripts for app #{@application}"
|
23
|
+
File.open("bin/start-#{@application}", 'w') do |f|
|
24
|
+
f.puts %q{root_path = File.join(File.dirname(__FILE__), '..')}
|
25
|
+
f.puts '`mongrel_rails start -d -c #{root_path}`'
|
26
|
+
end
|
27
|
+
File.open("bin/stop-#{@application}", 'w') do |f|
|
28
|
+
f.puts %q{root_path = File.join(File.dirname(__FILE__), '..')}
|
29
|
+
f.puts '`mongrel_rails stop -c #{root_path}`'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/capgem/utils.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Capgem
|
2
|
+
class Utils
|
3
|
+
# Create the required directories (bin and log) and put a README in the log
|
4
|
+
# directory
|
5
|
+
def self.create_directories
|
6
|
+
mkdir 'bin' unless File.exists?('bin')
|
7
|
+
mkdir 'log' unless File.exists?('log')
|
8
|
+
File.open('log/README') do |f|
|
9
|
+
puts "Log files will go here"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: capgem
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2006-06-26 00:00:00 -04:00
|
8
|
+
summary: Capistrano extension which builds a gem.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email:
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description: Capgem is an extension to Capistrano which builds your Rails app to a gem which can be installed anywhere.
|
15
|
+
autorequire: capgem
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/capgem
|
32
|
+
- lib/capgem.rb
|
33
|
+
- lib/capgem/gembuilder.rb
|
34
|
+
- lib/capgem/servers
|
35
|
+
- lib/capgem/utils.rb
|
36
|
+
- lib/capgem/servers/mongrel.rb
|
37
|
+
test_files: []
|
38
|
+
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
executables: []
|
44
|
+
|
45
|
+
extensions: []
|
46
|
+
|
47
|
+
requirements:
|
48
|
+
- none
|
49
|
+
dependencies: []
|
50
|
+
|