zorglub 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/node_spec.rb ADDED
@@ -0,0 +1,157 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ require 'spec_helper'
4
+ #
5
+ describe Zorglub do
6
+ #
7
+ describe Zorglub::Node do
8
+ #
9
+ it "engine should return default Node's engine" do
10
+ Node0.engine.should == Zorglub::Config.engine
11
+ Node0.engine.should == Zorglub::Config[:engine]
12
+ end
13
+ #
14
+ it "layout should return default Node's layout" do
15
+ Node0.layout.should == Zorglub::Config.layout
16
+ end
17
+ #
18
+ it "engine should return class defined Node's engine" do
19
+ Node1.engine.should == "engine-1"
20
+ Node3.engine.should == "engine-2"
21
+ end
22
+ #
23
+ it "layout should return class defined Node's layout" do
24
+ Node1.layout.should == "layout-1"
25
+ Node3.layout.should == "layout-2"
26
+ end
27
+ #
28
+ it "engine should return engine inherited from Node2" do
29
+ Node2.engine.should == "engine-1"
30
+ end
31
+ #
32
+ it "layout should return layout inherited from Node2" do
33
+ Node2.layout.should == "layout-1"
34
+ end
35
+ #
36
+ it "r should build a well formed path" do
37
+ Node1.r(1,'arg2',"some").should == "/node1/1/arg2/some"
38
+ end
39
+ #
40
+ it "instance level map should work" do
41
+ r = Node0.my_call '/with_2args/1/2'
42
+ h = YAML.load r.body[0]
43
+ h[:map].should == '/node0'
44
+ end
45
+ #
46
+ it "should return err404 response when no method found" do
47
+ Node0.respond_to?('noresponse').should be_false
48
+ r = Node0.my_call '/noresponse'
49
+ r.status.should == 404
50
+ end
51
+ #
52
+ it "simple method should respond" do
53
+ r = Node0.my_call '/hello'
54
+ r.status.should == 200
55
+ r.body[0].should == 'world'
56
+ end
57
+ #
58
+ it "instance level args should work" do
59
+ r = Node0.my_call '/with_2args/1/2'
60
+ h = YAML.load r.body[0]
61
+ h[:args][0].should == '1'
62
+ h[:args][1].should == '2'
63
+ end
64
+ #
65
+ it "should raise error when too much arguments" do
66
+ lambda{ r = Node0.my_call '/with_2args/1/2/3' }.should raise_error ArgumentError
67
+ end
68
+ #
69
+ it "layout proc, method level layout and engine definitions should work" do
70
+ r = Node0.my_call '/index'
71
+ r.status.should == 200
72
+ h = YAML.load r.body[0]
73
+ ly = File.join Zorglub::Config.root, Zorglub::Config.layout_dir, Node0.layout
74
+ vu = File.join Zorglub::Config.root, Zorglub::Config.view_dir, Node0.r, 'index'
75
+ h[:path].should == ly
76
+ h[:layout].should == ly
77
+ h[:view].should == vu
78
+ end
79
+ #
80
+ it "layout proc, method level layout and engine definitions should work" do
81
+ r = Node1.my_call '/index'
82
+ r.status.should == 200
83
+ h = YAML.load r.body[0]
84
+ ly = File.join Zorglub::Config.root, Zorglub::Config.layout_dir, 'main.spec'
85
+ vu = File.join Zorglub::Config.root, Zorglub::Config.view_dir, Node1.r, 'index.spec'
86
+ h[:path].should == ly
87
+ h[:layout].should == ly
88
+ h[:view].should == vu
89
+ end
90
+ #
91
+ it "before_all hook should work" do
92
+ Node3.before = 0
93
+ Node3.after = 0
94
+ Node3.before.should == 0
95
+ Node3.my_call '/index'
96
+ Node3.before.should == 1
97
+ Node3.my_call '/index'
98
+ Node3.before.should == 2
99
+ Node3.my_call '/index'
100
+ Node3.before.should == 3
101
+ end
102
+ #
103
+ it "after_all hook should work" do
104
+ Node3.before = 0
105
+ Node3.after = 0
106
+ Node3.after.should == 0
107
+ Node3.my_call '/index'
108
+ Node3.after.should == 1
109
+ Node3.my_call '/index'
110
+ Node3.after.should == 2
111
+ Node3.my_call '/index'
112
+ Node3.after.should == 3
113
+ end
114
+ #
115
+ it "should find view and layout and render them" do
116
+ r = Node0.my_call '/do_render'
117
+ r.status.should == 200
118
+ r.body[0].should == "layout_start view_content layout_end"
119
+ end
120
+ #
121
+ it "partial should render correctly" do
122
+ Node0.partial(:do_partial, 1, 2).should == 'partial_content'
123
+ end
124
+ #
125
+ it "method level view should work" do
126
+ Node0.partial(:other_view).should == 'partial_content'
127
+ end
128
+ #
129
+ it "redirect should work" do
130
+ r = Node0.my_call '/do_redirect'
131
+ r.status.should == 302
132
+ r.header['location'].should == Node0.r(:do_partial,1,2,3)
133
+ end
134
+ #
135
+ it "inherited_vars should be inherited and extended" do
136
+ r = Node5.my_call '/index'
137
+ vars = YAML.load r.body[0]
138
+ vars.should == ['js0','js1','js3','jsx','css0','css1','css2']
139
+ vars[7].should be_nil
140
+ end
141
+ #
142
+ it "inherited_vars should be extended at method level" do
143
+ r = Node4.my_call '/more'
144
+ vars = YAML.load r.body[0]
145
+ vars.should == ['js0','js1','js2']
146
+ vars[3].should be_nil
147
+ end
148
+ #
149
+ it "inherited_vars should be untouched" do
150
+ r = Node4.my_call '/index'
151
+ vars = YAML.load r.body[0]
152
+ vars.should == ['js0','js1']
153
+ vars[2].should be_nil
154
+ end
155
+ end
156
+ #
157
+ end
@@ -0,0 +1,136 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ begin
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter 'spec'
7
+ end
8
+ rescue LoadError
9
+ end
10
+ #
11
+ require 'yaml'
12
+ #
13
+ require 'zorglub'
14
+ #
15
+ HASH_PROC = Proc.new { |path,obj| {:path=>path,:layout=>obj.layout,:view=>obj.view,:args=>obj.args,:map=>obj.map}.to_yaml }
16
+ RENDER_PROC = Proc.new { |path,obj|
17
+ case obj.state
18
+ when :layout
19
+ "layout_start #{obj.content} layout_end"
20
+ when :view
21
+ "view_content"
22
+ when :partial
23
+ 'partial_content'
24
+ else
25
+ raise Exception.new
26
+ end
27
+ }
28
+ Zorglub::Config.register_engine 'default', nil, HASH_PROC
29
+ Zorglub::Config.register_engine 'engine-1', 'spec', HASH_PROC
30
+ Zorglub::Config.register_engine 'engine-2', 'spec', HASH_PROC
31
+ Zorglub::Config.register_engine 'real', nil, RENDER_PROC
32
+ #
33
+ Zorglub::Config[:engine] = 'default'
34
+ Zorglub::Config.root = File.join Dir.pwd, 'spec', 'data'
35
+ #
36
+ class Zorglub::Node
37
+ def self.my_call uri
38
+ call( {'PATH_INFO'=>uri} )
39
+ end
40
+ end
41
+ #
42
+ class Temp < Zorglub::Node
43
+ end
44
+ #
45
+ class Node0 < Zorglub::Node
46
+ # default
47
+ def index
48
+ html
49
+ end
50
+ def hello
51
+ no_layout
52
+ 'world'
53
+ end
54
+ def with_2args a1, a2
55
+ end
56
+ def do_render
57
+ engine 'real'
58
+ end
59
+ def do_partial a1, a2
60
+ engine 'real'
61
+ end
62
+ def other_view
63
+ engine 'real'
64
+ view r('do_partial')
65
+ end
66
+ def do_redirect
67
+ redirect r(:do_partial,1,2,3)
68
+ end
69
+ end
70
+ #
71
+ class Node1 < Zorglub::Node
72
+ layout 'layout-1'
73
+ engine 'engine-1'
74
+ def index
75
+ layout 'main'
76
+ engine 'engine-2'
77
+ end
78
+ end
79
+ #
80
+ class Node2 < Node1
81
+ # inherited from Node1
82
+ end
83
+ #
84
+ class Node3 < Zorglub::Node
85
+ @before=0
86
+ @after=0
87
+ class << self
88
+ attr_accessor :before, :after
89
+ end
90
+ before_all do |node|
91
+ Node3.before +=1
92
+ end
93
+ after_all do |node|
94
+ Node3.after +=1
95
+ end
96
+ layout 'layout-2'
97
+ engine 'engine-2'
98
+ def index
99
+ (self.class.before-self.class.after).should == 1
100
+ end
101
+ end
102
+ #
103
+ class Node4 < Zorglub::Node
104
+ inherited_var :js,'js0','js1'
105
+ def index
106
+ no_layout
107
+ inherited_var(:js).to_yaml
108
+ end
109
+ def more
110
+ no_layout
111
+ inherited_var(:js,'js2').to_yaml
112
+ end
113
+ end
114
+ #
115
+ class Node5 < Node4
116
+ inherited_var :js, 'js3'
117
+ inherited_var :css, 'css0', 'css1'
118
+ def index
119
+ no_layout
120
+ js = inherited_var(:js,'jsx')
121
+ css = inherited_var(:css, 'css0', 'css1','css2')
122
+ js.concat(css).to_yaml
123
+ end
124
+ end
125
+ #
126
+ APP = Zorglub::App.new do
127
+ map '/node0', Node0
128
+ map '/node1', Node1
129
+ map '/node3', Node3
130
+ map '/node4', Node4
131
+ map '/node5', Node5
132
+ end
133
+ class Node2
134
+ map APP, '/node2'
135
+ end
136
+ #
data/tasks/ann.rake ADDED
@@ -0,0 +1,83 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ begin
4
+ require 'bones/smtp_tls'
5
+ rescue LoadError
6
+ require 'net/smtp'
7
+ end
8
+ require 'time'
9
+
10
+ namespace :ann do
11
+
12
+ # A prerequisites task that all other tasks depend upon
13
+ task :prereqs
14
+ file PROJ.ann.file do
15
+ ann = PROJ.ann
16
+ puts "Generating #{ann.file}"
17
+ File.open(ann.file,'w') do |fd|
18
+ fd.puts("#{PROJ.name} version #{PROJ.version}")
19
+ fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
20
+ fd.puts(" #{PROJ.url}") if PROJ.url.valid?
21
+ fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
22
+ fd.puts
23
+ fd.puts("== DESCRIPTION")
24
+ fd.puts
25
+ fd.puts(PROJ.description)
26
+ fd.puts
27
+ fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
28
+ fd.puts
29
+ ann.paragraphs.each do |p|
30
+ fd.puts "== #{p.upcase}"
31
+ fd.puts
32
+ fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
33
+ fd.puts
34
+ end
35
+ fd.puts ann.text if ann.text
36
+ end
37
+ end
38
+
39
+ desc "Create an announcement file"
40
+ task :announcement => ['ann:prereqs', PROJ.ann.file]
41
+
42
+ desc "Send an email announcement"
43
+ task :email => ['ann:prereqs', PROJ.ann.file] do
44
+ ann = PROJ.ann
45
+ from = ann.email[:from] || Array(PROJ.authors).first || PROJ.email
46
+ to = Array(ann.email[:to])
47
+
48
+ ### build a mail header for RFC 822
49
+ rfc822msg = "From: #{from}\n"
50
+ rfc822msg << "To: #{to.join(',')}\n"
51
+ rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
52
+ rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
53
+ rfc822msg << "\n"
54
+ rfc822msg << "Date: #{Time.new.rfc822}\n"
55
+ rfc822msg << "Message-Id: "
56
+ rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
57
+ rfc822msg << File.read(ann.file)
58
+
59
+ params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
60
+ ann.email[key]
61
+ end
62
+
63
+ params[3] = (PROJ.ann.email[:from] || PROJ.email) if params[3].nil?
64
+
65
+ # if ann.email[:tls] and params[4].nil?
66
+ if params[4].nil?
67
+ STDOUT.write "Please enter your e-mail password (#{params[3]}): "
68
+ params[4] = STDIN.gets.chomp
69
+ end
70
+ # params = params.shift 2 if not ann.email[:tls]
71
+
72
+ ### send email
73
+ # TODO find a way to bypass /var/lib/gems/1.9/gems/bones-3.6.5/lib/bones/smtp_tls.rb which forces starttls usage
74
+ Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
75
+ end
76
+ end # namespace :ann
77
+
78
+ desc 'Alias to ann:announcement'
79
+ task :ann => 'ann:announcement'
80
+
81
+ CLOBBER << PROJ.ann.file
82
+
83
+ # EOF
@@ -0,0 +1,118 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ require 'rbconfig'
4
+
5
+ # Setup some constants
6
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
7
+
8
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
9
+
10
+ def quiet( &block )
11
+ io = [STDOUT.dup, STDERR.dup]
12
+ STDOUT.reopen DEV_NULL
13
+ STDERR.reopen DEV_NULL
14
+ block.call
15
+ ensure
16
+ STDOUT.reopen io.first
17
+ STDERR.reopen io.last
18
+ $stdout, $stderr = STDOUT, STDERR
19
+ end
20
+
21
+ BUILD_DIR = "build"
22
+
23
+ USE_RAKE_COMPILER = ( ( (RUBY_PLATFORM =~ /java/) ? false : true ) and test ?d, 'ext' )
24
+ if USE_RAKE_COMPILER
25
+ gem 'rake-compiler', '>=0.6.0'
26
+ require 'rake/extensiontask'
27
+ ENV['RUBY_CC_VERSION'] = '1.8.7:1.9.2'
28
+ end
29
+
30
+ LIBEXT = case RbConfig::CONFIG['host_os'].downcase
31
+ when /darwin/
32
+ "dylib"
33
+ when /mswin|mingw/
34
+ "dll"
35
+ else
36
+ RbConfig::CONFIG['DLEXT']
37
+ end
38
+
39
+ CPU = case RbConfig::CONFIG['host_cpu'].downcase
40
+ when /i[3456]86/
41
+ # Darwin always reports i686, even when running in 64bit mode
42
+ if RbConfig::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum)
43
+ "x86_64"
44
+ else
45
+ "i386"
46
+ end
47
+ when /amd64|x86_64/
48
+ "x86_64"
49
+ when /ppc64|powerpc64/
50
+ "powerpc64"
51
+ when /ppc|powerpc/
52
+ "powerpc"
53
+ else
54
+ RbConfig::CONFIG['host_cpu']
55
+ end
56
+
57
+ OS = case RbConfig::CONFIG['host_os'].downcase
58
+ when /linux/
59
+ "linux"
60
+ when /darwin/
61
+ "darwin"
62
+ when /freebsd/
63
+ "freebsd"
64
+ when /openbsd/
65
+ "openbsd"
66
+ when /sunos|solaris/
67
+ "solaris"
68
+ when /mswin|mingw/
69
+ "win32"
70
+ else
71
+ RbConfig::CONFIG['host_os'].downcase
72
+ end
73
+
74
+ CC=ENV['CC'] || RbConfig::CONFIG['CC'] || "gcc"
75
+
76
+ GMAKE = RbConfig::CONFIG['host_os'].downcase =~ /bsd|solaris/ ? "gmake" : "make"
77
+
78
+
79
+ DIFF = if WIN32 then 'diff.exe'
80
+ else
81
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
82
+ else 'diff' end
83
+ end unless defined? DIFF
84
+
85
+ SUDO = if WIN32 then ''
86
+ else
87
+ if quiet {system 'which sudo'} then 'sudo'
88
+ else '' end
89
+ end
90
+
91
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
92
+ RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
93
+ GEM = WIN32 ? 'gem.bat' : 'gem'
94
+
95
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
96
+ begin
97
+ require lib
98
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
99
+ rescue LoadError
100
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
101
+ end
102
+ end
103
+
104
+ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and system("svn --version 2>&1 > #{DEV_NULL}"))
105
+ HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and system("git --version 2>&1 > #{DEV_NULL}"))
106
+
107
+ # Add rake as a development dependency
108
+ #
109
+ PROJ.gem.development_dependencies << ['rake', '>=0.8.7']
110
+
111
+ # Add bones as a development dependency
112
+ #
113
+ if HAVE_BONES
114
+ bones_version = defined?(Bones::VERSION) ? Bones::VERSION : Bones.version
115
+ PROJ.gem.development_dependencies << ['bones', ">= #{bones_version}"]
116
+ end
117
+
118
+ # EOF
data/tasks/gem.rake ADDED
@@ -0,0 +1,196 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ require 'find'
4
+ require 'rake/packagetask'
5
+ require 'rubygems/user_interaction'
6
+ require 'rubygems/builder'
7
+
8
+ module Bones
9
+ class GemPackageTask < Rake::PackageTask
10
+ # Ruby GEM spec containing the metadata for this package. The
11
+ # name, version and package_files are automatically determined
12
+ # from the GEM spec and don't need to be explicitly provided.
13
+ #
14
+ attr_accessor :gem_spec
15
+
16
+ # Tasks from the Bones gem directory
17
+ attr_reader :bones_files
18
+
19
+ # Create a GEM Package task library. Automatically define the gem
20
+ # if a block is given. If no block is supplied, then +define+
21
+ # needs to be called to define the task.
22
+ #
23
+ def initialize(gem_spec)
24
+ init(gem_spec)
25
+ yield self if block_given?
26
+ define if block_given?
27
+ end
28
+
29
+ # Initialization tasks without the "yield self" or define
30
+ # operations.
31
+ #
32
+ def init(gem)
33
+ super(gem.name, gem.version)
34
+ @gem_spec = gem
35
+ @package_files += gem_spec.files if gem_spec.files
36
+ @bones_files = []
37
+
38
+ local_setup = File.join(Dir.pwd, %w[tasks setup.rb])
39
+ if !test(?e, local_setup)
40
+ Dir.glob(::Bones.path(%w[lib bones tasks *])).each {|fn| bones_files << fn}
41
+ end
42
+ end
43
+
44
+ # Create the Rake tasks and actions specified by this
45
+ # GemPackageTask. (+define+ is automatically called if a block is
46
+ # given to +new+).
47
+ #
48
+ def define
49
+ super
50
+ task :prereqs
51
+ task :package => ['gem:prereqs', "#{package_dir_path}/#{gem_file}"]
52
+ file "#{package_dir_path}/#{gem_file}" => [package_dir_path] + package_files + bones_files do
53
+ when_writing("Creating GEM") {
54
+ chdir(package_dir_path) do
55
+ Gem::Builder.new(gem_spec).build
56
+ verbose(true) { mv gem_file, "../#{gem_file}" }
57
+ end
58
+ }
59
+ end
60
+
61
+ file package_dir_path => bones_files do
62
+ mkdir_p package_dir rescue nil
63
+
64
+ gem_spec.files = (gem_spec.files + bones_files.map {|fn| File.join('tasks', File.basename(fn))}).sort
65
+
66
+ bones_files.each do |fn|
67
+ base_fn = File.join('tasks', File.basename(fn))
68
+ f = File.join(package_dir_path, base_fn)
69
+ fdir = File.dirname(f)
70
+ mkdir_p(fdir) if !File.exist?(fdir)
71
+ if File.directory?(fn)
72
+ mkdir_p(f)
73
+ else
74
+ raise "file name conflict for '#{base_fn}' (conflicts with '#{fn}')" if test(?e, f)
75
+ safe_ln(fn, f)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ def gem_file
82
+ if @gem_spec.platform == Gem::Platform::RUBY
83
+ "#{package_name}.gem"
84
+ else
85
+ "#{package_name}-#{@gem_spec.platform}.gem"
86
+ end
87
+ end
88
+ end # class GemPackageTask
89
+ end # module Bones
90
+
91
+ namespace :gem do
92
+
93
+ PROJ.gem._spec = Gem::Specification.new do |s|
94
+ s.name = PROJ.name
95
+ s.version = PROJ.version
96
+ s.summary = PROJ.summary
97
+ s.authors = Array(PROJ.authors)
98
+ s.email = PROJ.email
99
+ s.homepage = Array(PROJ.url).first
100
+ s.rubyforge_project = PROJ.rubyforge.name
101
+
102
+ s.description = PROJ.description
103
+
104
+ PROJ.gem.dependencies.each do |dep|
105
+ s.add_dependency(*dep)
106
+ end
107
+
108
+ PROJ.gem.development_dependencies.each do |dep|
109
+ s.add_development_dependency(*dep)
110
+ end
111
+
112
+ s.files = PROJ.gem.files
113
+ s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
114
+ s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
115
+
116
+ s.bindir = 'bin'
117
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
118
+ s.require_paths = dirs unless dirs.empty?
119
+
120
+ incl = Regexp.new(PROJ.rdoc.include.join('|'))
121
+ excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
122
+ excl = Regexp.new(excl.join('|'))
123
+ rdoc_files = PROJ.gem.files.find_all do |fn|
124
+ case fn
125
+ when excl; false
126
+ when incl; true
127
+ else false end
128
+ end
129
+ s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
130
+ s.extra_rdoc_files = rdoc_files
131
+
132
+ if test ?f, PROJ.test.file
133
+ s.test_file = PROJ.test.file
134
+ else
135
+ s.test_files = PROJ.test.files.to_a
136
+ end
137
+
138
+ # Do any extra stuff the user wants
139
+ PROJ.gem.extras.each do |msg, val|
140
+ case val
141
+ when Proc
142
+ val.call(s.send(msg))
143
+ else
144
+ s.send "#{msg}=", val
145
+ end
146
+ end
147
+ end # Gem::Specification.new
148
+
149
+ Bones::GemPackageTask.new(PROJ.gem._spec) do |pkg|
150
+ pkg.need_tar = PROJ.gem.need_tar
151
+ pkg.need_zip = PROJ.gem.need_zip
152
+ end
153
+
154
+ desc 'Show information about the gem'
155
+ task :debug => 'gem:prereqs' do
156
+ puts PROJ.gem._spec.to_ruby
157
+ end
158
+
159
+ desc 'Write the gemspec '
160
+ task :spec => 'gem:prereqs' do
161
+ File.open("#{PROJ.name}.gemspec", 'w') do |f|
162
+ f.write PROJ.gem._spec.to_ruby
163
+ end
164
+ end
165
+
166
+ desc 'Install the gem'
167
+ task :install => [:clobber, 'gem:package'] do
168
+ sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
169
+ # use this version of the command for rubygems > 1.0.0
170
+ #sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
171
+ end
172
+
173
+ desc 'Uninstall the gem'
174
+ task :uninstall do
175
+ installed_list = Gem.source_index.find_name(PROJ.name)
176
+ if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
177
+ sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
178
+ end
179
+ end
180
+
181
+ desc 'Reinstall the gem'
182
+ task :reinstall => [:uninstall, :install]
183
+
184
+ desc 'Cleanup the gem'
185
+ task :cleanup do
186
+ sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
187
+ end
188
+ end # namespace :gem
189
+
190
+ desc 'Alias to gem:package'
191
+ task :gem => 'gem:package'
192
+
193
+ task :clobber => 'gem:clobber_package'
194
+ remove_desc_for_task 'gem:clobber_package'
195
+
196
+ # EOF