cutagem 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 / 2007-10-07
2
+
3
+ * initial release
4
+
data/README ADDED
@@ -0,0 +1,125 @@
1
+
2
+ = cutagem - Cut a Gem for creating new beautiful gem.
3
+
4
+ by cho45 <cho45@lowreal.net>
5
+
6
+ == Description
7
+
8
+ cutagem (Cut a Gem) is yet another executable for creating gem skelton.
9
+
10
+ This is similar in concept to newgem[http://newgem.rubyforge.org/] but
11
+ more customizable for each users.
12
+
13
+ == Concept
14
+
15
+ * User customizable templates.
16
+ * Not use hoe, etc. Because it makes difficult to customize the created Rakefile.
17
+ A time like this, copy and paste is better than DRY.
18
+
19
+ == Installation
20
+
21
+ === Gem Installation
22
+
23
+ gem install cutagem
24
+
25
+ === Subversion Repository
26
+
27
+ Hosted by CodeRepos[http://coderepos.org/share/browser/lang/ruby/cutagem]
28
+
29
+ svn co http://svn.coderepos.org/share/lang/ruby/cutagem/
30
+
31
+ == Usage
32
+
33
+ Most simple sample:
34
+
35
+ $ cutagem gemname
36
+ Using Template: .cutagem/templates/default
37
+ cp -r /Users/cho45/.cutagem/templates/default /Users/cho45/tmp/gemname
38
+ Done.
39
+
40
+ When +gemname+ includes hyphens, it's replaced with "/".
41
+
42
+ $ cutagem module-test
43
+ Using Template: .cutagem/templates/default
44
+ cp -r /Users/cho45/.cutagem/templates/default /Users/cho45/tmp/module-test
45
+ Done
46
+
47
+ $ ls module-test/lib/module/test.rb
48
+ module-test/lib/module/test.rb
49
+
50
+
51
+ Select templates interactively. (<code>-s</code>, <code>--select</code> option)
52
+
53
+ $ cutagem -s module-test
54
+ Select template:
55
+ 1. .cutagem/templates/default
56
+ 2. default
57
+ 3. command
58
+ 1
59
+ cp -r /Users/cho45/.cutagem/templates/default /Users/cho45/tmp/module-test
60
+ Done
61
+
62
+ == Customization
63
+
64
+ +cutagem+ reads ~/.cutagem/template/* for using it as custom template.
65
+ Especially "default" template is precedence.
66
+
67
+ === Priority Example
68
+
69
+ Library installed templates:
70
+
71
+ * default
72
+ * command
73
+
74
+ User templates:
75
+
76
+ * ~/.cutagem/template/default
77
+ * ~/.cutagem/template/foobar
78
+
79
+ Priority order:
80
+
81
+ 1. ~/.cutagem/template/default
82
+ 2. ~/.cutagem/template/foobar
83
+ 3. default (system)
84
+ 4. command (system)
85
+
86
+ If you want to check this priority, add <code>-s</code>, <code>--select</code> option to +cutagem+.
87
+
88
+
89
+ === Template Spec.
90
+
91
+ ==== File Name Replacement
92
+
93
+ [gemname]
94
+ The argument +gemname+.
95
+ [gempath]
96
+ The string created by replacing "-" with "/" of +gemname+.
97
+ (ex. gemname is <code>hoge-hoge</code> then, gempath is <code>hoge/hoge</code>)
98
+ The path is automatically created.
99
+
100
+ ==== ERB Replacement
101
+
102
+ All files process through ERB.
103
+
104
+ [<%=gemname%>]
105
+ same as filename.
106
+ [<%=gempath%>]
107
+ same as filename.
108
+ [<%=gemclass%>]
109
+ classfied gemname.
110
+ (ex. gemname is <code>hoge-hoge_fuga</code> then, gemclass is <code>Hoge/HogeFuga</code>)
111
+ [<%=author%>]
112
+ ENV["USER"]
113
+ [<%=email%>]
114
+ <code>#{ENV["USER"]}@#{ENV["HOST"]}</code>
115
+ [<%=description%>]
116
+ <code>-d</code>, <code>--desc</code> option's value
117
+
118
+ Of course ERB is Ruby, you can write everything in the bracket.
119
+
120
+ == Copyright
121
+
122
+ Author:: cho45 <cho45@lowreal.net>
123
+ Copyright:: Copyright (c) 2007 cho45 www.lowreal.net
124
+ License:: Ruby's
125
+
data/Rakefile ADDED
@@ -0,0 +1,136 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'rubyforge'
11
+ include FileUtils
12
+
13
+ AUTHOR = "cho45"
14
+ EMAIL = "cho45@lowreal.net"
15
+ DESCRIPTION = "More safe eval codes."
16
+ RUBYFORGE_PROJECT = "cutagem"
17
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
18
+ BIN_FILES = %w( cutagem )
19
+
20
+ #VERS = File.read("#{File.dirname(__FILE__)}/bin/cutagem")[/VERSION = "(\d\.\d\.\d)"/, 1]
21
+ load "#{File.dirname(__FILE__)}/lib/cutagem.rb"
22
+ VERS = CutAGemCommand::VERSION
23
+
24
+
25
+ NAME = "cutagem"
26
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
27
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
28
+ RDOC_OPTS = ['--title', "#{NAME} documentation",
29
+ "--charset", "utf-8",
30
+ "--opname", "index.html",
31
+ "--line-numbers",
32
+ "--main", "README",
33
+ "--inline-source",
34
+ ]
35
+
36
+ desc "Packages up #{NAME} gem."
37
+ task :default => [:test]
38
+ task :package => [:clean]
39
+
40
+ Rake::TestTask.new("test") { |t|
41
+ t.libs << "test"
42
+ t.pattern = "test/**/*_test.rb"
43
+ t.verbose = true
44
+ }
45
+
46
+ spec = Gem::Specification.new do |s|
47
+ s.name = NAME
48
+ s.version = VERS
49
+ s.platform = Gem::Platform::RUBY
50
+ s.has_rdoc = true
51
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
52
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
53
+ s.summary = DESCRIPTION
54
+ s.description = DESCRIPTION
55
+ s.author = AUTHOR
56
+ s.email = EMAIL
57
+ s.homepage = HOMEPATH
58
+ s.executables = BIN_FILES
59
+ s.rubyforge_project = RUBYFORGE_PROJECT
60
+ s.bindir = "bin"
61
+ s.require_path = "lib"
62
+ s.autorequire = ""
63
+ s.test_files = Dir["test/test_*.rb"]
64
+
65
+ #s.add_dependency('activesupport', '>=1.3.1')
66
+ #s.required_ruby_version = '>= 1.8.2'
67
+
68
+ s.files = %w(README CHANGELOG Rakefile) +
69
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
70
+ Dir.glob("ext/**/*.{h,c,rb}") +
71
+ Dir.glob("examples/**/*.rb") +
72
+ Dir.glob("templates/**/*") +
73
+ Dir.glob("tools/*.rb")
74
+
75
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
76
+ end
77
+
78
+ Rake::GemPackageTask.new(spec) do |p|
79
+ p.need_tar = true
80
+ p.gem_spec = spec
81
+ end
82
+
83
+ task :install do
84
+ name = "#{NAME}-#{VERS}.gem"
85
+ sh %{rake package}
86
+ sh %{sudo gem install pkg/#{name}}
87
+ end
88
+
89
+ task :uninstall => [:clean] do
90
+ sh %{sudo gem uninstall #{NAME}}
91
+ end
92
+
93
+
94
+ Rake::RDocTask.new do |rdoc|
95
+ rdoc.rdoc_dir = 'html'
96
+ rdoc.options += RDOC_OPTS
97
+ rdoc.template = "#{ENV["HOME"]}/coderepos/lang/ruby/rdoc/generators/template/html/resh/resh.rb"
98
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
99
+ if ENV['DOC_FILES']
100
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
101
+ else
102
+ rdoc.rdoc_files.include('README', 'CHANGELOG')
103
+ rdoc.rdoc_files.include('lib/**/*.rb')
104
+ rdoc.rdoc_files.include('ext/**/*.c')
105
+ rdoc.rdoc_files.include('bin/**/*')
106
+ end
107
+ end
108
+
109
+ desc "Publish to RubyForge"
110
+ task :rubyforge => [:rdoc, :package] do
111
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'cho45').upload
112
+ end
113
+
114
+ desc 'Package and upload the release to rubyforge.'
115
+ task :release => [:clean, :package] do |t|
116
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
117
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
118
+ pkg = "pkg/#{NAME}-#{VERS}"
119
+
120
+ rf = RubyForge.new
121
+ puts "Logging in"
122
+ rf.login
123
+
124
+ c = rf.userconfig
125
+ # c["release_notes"] = description if description
126
+ # c["release_changes"] = changes if changes
127
+ c["preformatted"] = true
128
+
129
+ files = [
130
+ "#{pkg}.tgz",
131
+ "#{pkg}.gem"
132
+ ].compact
133
+
134
+ puts "Releasing #{NAME} v. #{VERS}"
135
+ rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
136
+ end
data/bin/cutagem ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # vim:ft=ruby:
3
+
4
+ require "rubygems"
5
+ require "cutagem"
6
+
7
+ CutAGemCommand.new(ARGV).run
data/lib/cutagem.rb ADDED
@@ -0,0 +1,148 @@
1
+
2
+ require "optparse"
3
+ require "pathname"
4
+ require "fileutils"
5
+ require "erb"
6
+
7
+ class CutAGemCommand
8
+ VERSION = "0.0.1"
9
+
10
+ include FileUtils
11
+ def self.run(argv)
12
+ new(argv.dup).run
13
+ end
14
+
15
+ def initialize(argv)
16
+ @argv = argv
17
+
18
+ @parser = OptionParser.new do |parser|
19
+ parser.banner = <<-EOB.gsub(/^\t+/, "")
20
+ Usage: #$0 [options] gemname
21
+ EOB
22
+
23
+ parser.separator ""
24
+ parser.separator "Options:"
25
+
26
+ parser.on("-s", "--select", "Select template interactively.") do |@select|
27
+ end
28
+
29
+ parser.on("-d", "--desc", "Describe this gem.") do |@description|
30
+ end
31
+
32
+ parser.on("--version", "Show version string `#{VERSION}'") do
33
+ puts VERSION
34
+ exit
35
+ end
36
+ end
37
+ end
38
+
39
+ def run
40
+ @parser.order!(@argv)
41
+ unless @argv.first
42
+ puts "gemname must be required."
43
+ exit
44
+ end
45
+
46
+ @templates = Pathname.new(File.dirname(__FILE__)).realpath + '../templates'
47
+ @user_templates = Pathname.new(ENV["HOME"]).realpath + '.cutagem/templates'
48
+
49
+ templates = []
50
+ u_templates = []
51
+ if @user_templates.exist?
52
+ Pathname.glob(@user_templates + "*").each do |t|
53
+ t = [".cutagem/templates/#{t.basename}", t]
54
+ if t[1].basename.to_s == "default"
55
+ u_templates.unshift(t)
56
+ else
57
+ u_templates << t
58
+ end
59
+ end
60
+ end
61
+ Pathname.glob(@templates + "*").each do |t|
62
+ t = ["#{t.basename}", t]
63
+ if t[1].basename.to_s == "default"
64
+ templates.unshift(t)
65
+ else
66
+ templates << t
67
+ end
68
+ end
69
+ templates = u_templates + templates
70
+
71
+ pwd = Pathname.pwd
72
+
73
+ author = ENV['USER']
74
+ email = "#{ENV['USER']}@#{ENV['HOST']}"
75
+ gemname = @argv.shift
76
+ gemid = gemname.gsub("-", "")
77
+ gempath = gemname.gsub("-", "/")
78
+ gemclass = gempath.split("/").map {|c|
79
+ c.split(/_/).collect {|i| i.capitalize }.join("")
80
+ }.join("::")
81
+ description = @description
82
+
83
+ template = nil
84
+ if @select
85
+ puts "Select template:"
86
+ templates.each_with_index do |item,index|
87
+ puts "% 2d. %s" % [index+1, item.first]
88
+ end
89
+ input = gets.chomp
90
+ case input
91
+ when ""
92
+ template = templates.first
93
+ when /^\d+$/
94
+ template = templates[input.to_i-1]
95
+ else
96
+ template = nil
97
+ puts "Canceled"
98
+ exit
99
+ end
100
+ else
101
+ template = templates.first
102
+ end
103
+ unless template
104
+ puts "Not select template."
105
+ exit
106
+ end
107
+ puts "Using Template: %s" % template
108
+ template = template[1]
109
+
110
+ gemdir = pwd + gemname
111
+
112
+ if gemdir.exist?
113
+ puts "#{gemdir.basename} is already exists."
114
+ exit
115
+ end
116
+
117
+ begin
118
+ cp_r template, gemdir, :verbose => true
119
+ Pathname.glob(gemdir + "**/gemname*") do |f|
120
+ f.rename(f.parent + f.basename.to_s.sub(/gemname/, gemname))
121
+ end
122
+ Pathname.glob(gemdir + "**/gempath*") do |f|
123
+ g = f.parent + f.basename.to_s.sub(/gempath/, gempath)
124
+ g.parent.mkpath
125
+ f.rename(g)
126
+ end
127
+ Pathname.glob(gemdir + "**/*") do |f|
128
+ next unless f.file?
129
+ f.open("r+") do |f|
130
+ content = f.read
131
+ f.rewind
132
+ f.puts ERB.new(content).result(binding)
133
+ f.truncate(f.tell)
134
+ end
135
+ end
136
+ rescue
137
+ gemdir.rmtree
138
+ raise
139
+ end
140
+
141
+ puts "Done."
142
+ if ENV["EDITOR"]
143
+ puts "Type any key to edit Rakefile."
144
+ gets
145
+ exec(ENV["EDITOR"], gemdir + "Rakefile")
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,4 @@
1
+ == 0.0.1 / <%=Time.now.strftime("%Y-%m-%d")%>
2
+
3
+ * initial release
4
+
@@ -0,0 +1,29 @@
1
+
2
+ = <%=gemname%>
3
+
4
+
5
+ == Description
6
+
7
+
8
+ == Installation
9
+
10
+ === Archive Installation
11
+
12
+ rake install
13
+
14
+ === Gem Installation
15
+
16
+ gem install <%=gemid%>
17
+
18
+
19
+ == Features/Problems
20
+
21
+
22
+ == Synopsys
23
+
24
+
25
+ == Copyright
26
+
27
+ Author:: <%=ENV['USER']%> <<%=email%>>
28
+ Copyright:: Copyright (c) 2007 <%=ENV['USER']%>
29
+ License::
@@ -0,0 +1,130 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ include FileUtils
11
+
12
+ AUTHOR = "<%=author%>"
13
+ EMAIL = "<%=email%>"
14
+ DESCRIPTION = "<%=description%>"
15
+ RUBYFORGE_PROJECT = "<%=gemid%>"
16
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
17
+ BIN_FILES = %w( )
18
+ VERS = "0.0.1"
19
+
20
+
21
+ NAME = "<%=gemname%>"
22
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
24
+ RDOC_OPTS = ['--title', "#{NAME} documentation",
25
+ "--charset", "utf-8",
26
+ "--opname", "index.html",
27
+ "--line-numbers",
28
+ "--main", "README",
29
+ "--inline-source",
30
+ ]
31
+
32
+ desc "Packages up #{NAME} gem."
33
+ task :default => [:test]
34
+ task :package => [:clean]
35
+
36
+ Rake::TestTask.new("test") { |t|
37
+ t.libs << "test"
38
+ t.pattern = "test/**/*_test.rb"
39
+ t.verbose = true
40
+ }
41
+
42
+ spec = Gem::Specification.new do |s|
43
+ s.name = NAME
44
+ s.version = VERS
45
+ s.platform = Gem::Platform::RUBY
46
+ s.has_rdoc = true
47
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
48
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
49
+ s.summary = DESCRIPTION
50
+ s.description = DESCRIPTION
51
+ s.author = AUTHOR
52
+ s.email = EMAIL
53
+ s.homepage = HOMEPATH
54
+ s.executables = BIN_FILES
55
+ s.rubyforge_project = RUBYFORGE_PROJECT
56
+ s.bindir = "bin"
57
+ s.require_path = "lib"
58
+ s.autorequire = ""
59
+ s.test_files = Dir["test/test_*.rb"]
60
+
61
+ #s.add_dependency('activesupport', '>=1.3.1')
62
+ #s.required_ruby_version = '>= 1.8.2'
63
+
64
+ s.files = %w(README CHANGELOG Rakefile) +
65
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
66
+ Dir.glob("ext/**/*.{h,c,rb}") +
67
+ Dir.glob("examples/**/*.rb") +
68
+ Dir.glob("tools/*.rb")
69
+
70
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
71
+ end
72
+
73
+ Rake::GemPackageTask.new(spec) do |p|
74
+ p.need_tar = true
75
+ p.gem_spec = spec
76
+ end
77
+
78
+ task :install do
79
+ name = "#{NAME}-#{VERS}.gem"
80
+ sh %{rake package}
81
+ sh %{sudo gem install pkg/#{name}}
82
+ end
83
+
84
+ task :uninstall => [:clean] do
85
+ sh %{sudo gem uninstall #{NAME}}
86
+ end
87
+
88
+
89
+ Rake::RDocTask.new do |rdoc|
90
+ rdoc.rdoc_dir = 'html'
91
+ rdoc.options += RDOC_OPTS
92
+ rdoc.template = "#{ENV["HOME"]}/coderepos/lang/ruby/rdoc/generators/template/html/resh/resh.rb"
93
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
94
+ if ENV['DOC_FILES']
95
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
96
+ else
97
+ rdoc.rdoc_files.include('README', 'CHANGELOG')
98
+ rdoc.rdoc_files.include('lib/**/*.rb')
99
+ rdoc.rdoc_files.include('ext/**/*.c')
100
+ end
101
+ end
102
+
103
+ desc "Publish to RubyForge"
104
+ task :rubyforge => [:rdoc, :package] do
105
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, '<%=ENV['USER']%>').upload
106
+ end
107
+
108
+ desc 'Package and upload the release to rubyforge.'
109
+ task :release => [:clean, :package] do |t|
110
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
111
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
112
+ pkg = "pkg/#{NAME}-#{VERS}"
113
+
114
+ rf = RubyForge.new
115
+ puts "Logging in"
116
+ rf.login
117
+
118
+ c = rf.userconfig
119
+ # c["release_notes"] = description if description
120
+ # c["release_changes"] = changes if changes
121
+ c["preformatted"] = true
122
+
123
+ files = [
124
+ "#{pkg}.tgz",
125
+ "#{pkg}.gem"
126
+ ].compact
127
+
128
+ puts "Releasing #{NAME} v. #{VERS}"
129
+ rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
130
+ end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # vim:ft=ruby:
3
+
4
+ require "optparse"
5
+ require "pathname"
6
+
7
+ class <%=gemclass.gsub(/::/, "")%>Command
8
+ VERSION = "0.0.1"
9
+
10
+ include FileUtils
11
+ def self.run(argv)
12
+ new(argv.dup).run
13
+ end
14
+
15
+ def initialize(argv)
16
+ @argv = argv
17
+
18
+ @parser = OptionParser.new do |parser|
19
+ parser.banner = <<-EOB.gsub(/^\t+/, "")
20
+ Usage: #$0 [options]
21
+ EOB
22
+
23
+ parser.separator ""
24
+ parser.separator "Options:"
25
+
26
+ parser.on("--version", "Show version string `#{VERSION}'") do
27
+ puts VERSION
28
+ exit
29
+ end
30
+ end
31
+ end
32
+
33
+ def run
34
+ @parser.order!(@argv)
35
+
36
+ # write
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "test/unit"
4
+ class <%=gemclass%>Test < Test::Unit::TestCase
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/<%=gempath%>'
3
+
@@ -0,0 +1,4 @@
1
+ == 0.0.1 / <%=Time.now.strftime("%Y-%m-%d")%>
2
+
3
+ * initial release
4
+
@@ -0,0 +1,29 @@
1
+
2
+ = <%=gemname%>
3
+
4
+
5
+ == Description
6
+
7
+
8
+ == Installation
9
+
10
+ === Archive Installation
11
+
12
+ rake install
13
+
14
+ === Gem Installation
15
+
16
+ gem install <%=gemid%>
17
+
18
+
19
+ == Features/Problems
20
+
21
+
22
+ == Synopsys
23
+
24
+
25
+ == Copyright
26
+
27
+ Author:: <%=ENV['USER']%> <<%=email%>>
28
+ Copyright:: Copyright (c) 2007 <%=ENV['USER']%>
29
+ License::
@@ -0,0 +1,130 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ include FileUtils
11
+
12
+ AUTHOR = "<%=author%>"
13
+ EMAIL = "<%=email%>"
14
+ DESCRIPTION = "<%=description%>"
15
+ RUBYFORGE_PROJECT = "<%=gemid%>"
16
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
17
+ BIN_FILES = %w( )
18
+ VERS = "0.0.1"
19
+
20
+
21
+ NAME = "<%=gemname%>"
22
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
24
+ RDOC_OPTS = ['--title', "#{NAME} documentation",
25
+ "--charset", "utf-8",
26
+ "--opname", "index.html",
27
+ "--line-numbers",
28
+ "--main", "README",
29
+ "--inline-source",
30
+ ]
31
+
32
+ desc "Packages up #{NAME} gem."
33
+ task :default => [:test]
34
+ task :package => [:clean]
35
+
36
+ Rake::TestTask.new("test") { |t|
37
+ t.libs << "test"
38
+ t.pattern = "test/**/*_test.rb"
39
+ t.verbose = true
40
+ }
41
+
42
+ spec = Gem::Specification.new do |s|
43
+ s.name = NAME
44
+ s.version = VERS
45
+ s.platform = Gem::Platform::RUBY
46
+ s.has_rdoc = true
47
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
48
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
49
+ s.summary = DESCRIPTION
50
+ s.description = DESCRIPTION
51
+ s.author = AUTHOR
52
+ s.email = EMAIL
53
+ s.homepage = HOMEPATH
54
+ s.executables = BIN_FILES
55
+ s.rubyforge_project = RUBYFORGE_PROJECT
56
+ s.bindir = "bin"
57
+ s.require_path = "lib"
58
+ s.autorequire = ""
59
+ s.test_files = Dir["test/test_*.rb"]
60
+
61
+ #s.add_dependency('activesupport', '>=1.3.1')
62
+ #s.required_ruby_version = '>= 1.8.2'
63
+
64
+ s.files = %w(README CHANGELOG Rakefile) +
65
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
66
+ Dir.glob("ext/**/*.{h,c,rb}") +
67
+ Dir.glob("examples/**/*.rb") +
68
+ Dir.glob("tools/*.rb")
69
+
70
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
71
+ end
72
+
73
+ Rake::GemPackageTask.new(spec) do |p|
74
+ p.need_tar = true
75
+ p.gem_spec = spec
76
+ end
77
+
78
+ task :install do
79
+ name = "#{NAME}-#{VERS}.gem"
80
+ sh %{rake package}
81
+ sh %{sudo gem install pkg/#{name}}
82
+ end
83
+
84
+ task :uninstall => [:clean] do
85
+ sh %{sudo gem uninstall #{NAME}}
86
+ end
87
+
88
+
89
+ Rake::RDocTask.new do |rdoc|
90
+ rdoc.rdoc_dir = 'html'
91
+ rdoc.options += RDOC_OPTS
92
+ rdoc.template = "#{ENV["HOME"]}/coderepos/lang/ruby/rdoc/generators/template/html/resh/resh.rb"
93
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
94
+ if ENV['DOC_FILES']
95
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
96
+ else
97
+ rdoc.rdoc_files.include('README', 'CHANGELOG')
98
+ rdoc.rdoc_files.include('lib/**/*.rb')
99
+ rdoc.rdoc_files.include('ext/**/*.c')
100
+ end
101
+ end
102
+
103
+ desc "Publish to RubyForge"
104
+ task :rubyforge => [:rdoc, :package] do
105
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, '<%=ENV['USER']%>').upload
106
+ end
107
+
108
+ desc 'Package and upload the release to rubyforge.'
109
+ task :release => [:clean, :package] do |t|
110
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
111
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
112
+ pkg = "pkg/#{NAME}-#{VERS}"
113
+
114
+ rf = RubyForge.new
115
+ puts "Logging in"
116
+ rf.login
117
+
118
+ c = rf.userconfig
119
+ # c["release_notes"] = description if description
120
+ # c["release_changes"] = changes if changes
121
+ c["preformatted"] = true
122
+
123
+ files = [
124
+ "#{pkg}.tgz",
125
+ "#{pkg}.gem"
126
+ ].compact
127
+
128
+ puts "Releasing #{NAME} v. #{VERS}"
129
+ rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
130
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class <%=gemclass%>
3
+
4
+ end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "test/unit"
4
+ class <%=gemclass%>Test < Test::Unit::TestCase
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/<%=gempath%>'
3
+
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "test/unit"
4
+ class SafeEvalTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @t = SafeEval.new.taint
8
+ end
9
+
10
+ def test_interface
11
+ assert_nothing_raised do
12
+ @t.safe_eval(":foo")
13
+ end
14
+
15
+ assert_nothing_raised do
16
+ @t.eval(":foo")
17
+ end
18
+
19
+ assert_nothing_raised do
20
+ SafeEval.eval(":foo")
21
+ end
22
+ end
23
+
24
+ def test_safe
25
+ assert_raise(SecurityError) do
26
+ @t.safe_eval("puts ''")
27
+ end
28
+
29
+ assert_raise(SecurityError) do
30
+ @t.safe_eval("$foo = :foo")
31
+ end
32
+ end
33
+
34
+ def test_thread
35
+ a = Thread.list.size
36
+ ret = @t.safe_eval <<-EOC
37
+ Thread.start {
38
+ sleep
39
+ }
40
+ EOC
41
+ assert_equal(a, Thread.list.size)
42
+
43
+ a = Thread.list.size
44
+ ret = @t.safe_eval <<-EOC
45
+ 100.times do
46
+ Thread.start {
47
+ sleep
48
+ }
49
+ end
50
+ EOC
51
+ assert_equal(a, Thread.list.size)
52
+ end
53
+
54
+ def test_timeout
55
+ assert_raise(Timeout::Error) do
56
+ @t.safe_eval("sleep", 0.1)
57
+ end
58
+
59
+ assert_nothing_raised(Timeout::Error) do
60
+ @t.safe_eval("nil", 0.1)
61
+ end
62
+
63
+ end
64
+
65
+ def test_define_method
66
+ # failed on ruby1.9 (2007-09-24)
67
+ assert_nothing_raised(SecurityError) do
68
+ @t.safe_eval("def hoge; end")
69
+ end
70
+
71
+ @t.safe_eval <<-EOS
72
+ def safe_eval(code)
73
+ "Nice boat."
74
+ end
75
+ EOS
76
+ assert_not_equal("Nice boat", @t.safe_eval("nil"))
77
+ end
78
+
79
+ def test_safe_access
80
+ assert_raise(NoMethodError) do
81
+ @t.safe_eval("@foo << :bar")
82
+ end
83
+ assert_equal(nil, @t.instance_variable_get(:@foo))
84
+
85
+ assert_raise(NameError) do
86
+ @t.safe_eval("@@foo")
87
+ end
88
+
89
+ assert_raise(SecurityError) do
90
+ @t.safe_eval("@@foo = :foo")
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/safe_eval'
3
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: cutagem
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-10-07 00:00:00 +09:00
8
+ summary: More safe eval codes.
9
+ require_paths:
10
+ - lib
11
+ email: cho45@lowreal.net
12
+ homepage: http://cutagem.rubyforge.org
13
+ rubyforge_project: cutagem
14
+ description: More safe eval codes.
15
+ autorequire: ''
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - cho45
32
+ files:
33
+ - README
34
+ - CHANGELOG
35
+ - Rakefile
36
+ - bin/cutagem
37
+ - test/cutagem_test.rb
38
+ - test/test_helper.rb
39
+ - lib/cutagem.rb
40
+ - templates/command
41
+ - templates/default
42
+ - templates/command/bin
43
+ - templates/command/CHANGELOG
44
+ - templates/command/lib
45
+ - templates/command/Rakefile
46
+ - templates/command/README
47
+ - templates/command/test
48
+ - templates/command/bin/gemname
49
+ - templates/command/test/gemname_test.rb
50
+ - templates/command/test/test_helper.rb
51
+ - templates/default/bin
52
+ - templates/default/CHANGELOG
53
+ - templates/default/lib
54
+ - templates/default/Rakefile
55
+ - templates/default/README
56
+ - templates/default/test
57
+ - templates/default/lib/gempath.rb
58
+ - templates/default/test/gemname_test.rb
59
+ - templates/default/test/test_helper.rb
60
+ test_files:
61
+ - test/test_helper.rb
62
+ rdoc_options:
63
+ - "--title"
64
+ - cutagem documentation
65
+ - "--charset"
66
+ - utf-8
67
+ - "--opname"
68
+ - index.html
69
+ - "--line-numbers"
70
+ - "--main"
71
+ - README
72
+ - "--inline-source"
73
+ - "--exclude"
74
+ - "^(examples|extras)/"
75
+ extra_rdoc_files:
76
+ - README
77
+ - CHANGELOG
78
+ executables:
79
+ - cutagem
80
+ extensions: []
81
+ requirements: []
82
+ dependencies: []