cutagem 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -2
- data/ChangeLog +4 -0
- data/README +23 -2
- data/Rakefile +1 -1
- data/lib/cutagem.rb +89 -52
- data/templates/command/{CHANGELOG → ChangeLog} +0 -0
- data/templates/command/Rakefile +1 -1
- data/templates/default/{CHANGELOG → ChangeLog} +0 -0
- data/templates/default/Rakefile +1 -1
- data/test/cutagem_test.rb +2 -89
- data/test/test_helper.rb +1 -1
- metadata +5 -4
data/CHANGELOG
CHANGED
data/ChangeLog
ADDED
data/README
CHANGED
@@ -59,11 +59,30 @@ Select templates interactively. (<code>-s</code>, <code>--select</code> option)
|
|
59
59
|
cp -r /Users/cho45/.cutagem/templates/default /Users/cho45/tmp/module-test
|
60
60
|
Done
|
61
61
|
|
62
|
+
Edit user configuration.
|
63
|
+
|
64
|
+
$ cutagem -c
|
65
|
+
[Open ~/.cutagem/config.yaml with $EDITOR]
|
66
|
+
|
67
|
+
Other options:
|
68
|
+
|
69
|
+
Usage: cutagem [options] gemname
|
70
|
+
|
71
|
+
Options:
|
72
|
+
-s, --select Select template interactively.
|
73
|
+
-d, --desc Describe this gem.
|
74
|
+
-c, --config Configure user values. Use vim
|
75
|
+
--copy-template NAME Copy template to user template dir naming NAME
|
76
|
+
--version Show version string `0.0.2'
|
77
|
+
|
78
|
+
|
62
79
|
== Customization
|
63
80
|
|
64
81
|
+cutagem+ reads ~/.cutagem/template/* for using it as custom template.
|
65
82
|
Especially "default" template is precedence.
|
66
83
|
|
84
|
+
You can make new template by coping the existing template using '--copy-template NAME' option.
|
85
|
+
|
67
86
|
=== Priority Example
|
68
87
|
|
69
88
|
Library installed templates:
|
@@ -109,11 +128,13 @@ All files process through ERB.
|
|
109
128
|
classfied gemname.
|
110
129
|
(ex. gemname is <code>hoge-hoge_fuga</code> then, gemclass is <code>Hoge/HogeFuga</code>)
|
111
130
|
[<%=author%>]
|
112
|
-
ENV["USER"]
|
131
|
+
ENV["USER"] or ~/.cutagem/config.yaml#author
|
113
132
|
[<%=email%>]
|
114
|
-
<code>#{ENV["USER"]}@#{ENV["HOST"]}</code>
|
133
|
+
<code>#{ENV["USER"]}@#{ENV["HOST"]}</code> or ~/.cutagem/config.yaml#email
|
115
134
|
[<%=description%>]
|
116
135
|
<code>-d</code>, <code>--desc</code> option's value
|
136
|
+
[<%=config["user_config_value"]%>]
|
137
|
+
Replace with ~/.cutagem/config.yaml entry.
|
117
138
|
|
118
139
|
Of course ERB is Ruby, you can write everything in the bracket.
|
119
140
|
|
data/Rakefile
CHANGED
@@ -48,7 +48,7 @@ spec = Gem::Specification.new do |s|
|
|
48
48
|
s.version = VERS
|
49
49
|
s.platform = Gem::Platform::RUBY
|
50
50
|
s.has_rdoc = true
|
51
|
-
s.extra_rdoc_files = ["README", "
|
51
|
+
s.extra_rdoc_files = ["README", "ChangeLog"]
|
52
52
|
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
53
53
|
s.summary = DESCRIPTION
|
54
54
|
s.description = DESCRIPTION
|
data/lib/cutagem.rb
CHANGED
@@ -3,9 +3,10 @@ require "optparse"
|
|
3
3
|
require "pathname"
|
4
4
|
require "fileutils"
|
5
5
|
require "erb"
|
6
|
+
require "yaml"
|
6
7
|
|
7
8
|
class CutAGemCommand
|
8
|
-
VERSION = "0.0.
|
9
|
+
VERSION = "0.0.2"
|
9
10
|
|
10
11
|
include FileUtils
|
11
12
|
def self.run(argv)
|
@@ -15,6 +16,7 @@ class CutAGemCommand
|
|
15
16
|
def initialize(argv)
|
16
17
|
@argv = argv
|
17
18
|
|
19
|
+
@config = Pathname.new(ENV["HOME"]) + ".cutagem/config.yaml"
|
18
20
|
@parser = OptionParser.new do |parser|
|
19
21
|
parser.banner = <<-EOB.gsub(/^\t+/, "")
|
20
22
|
Usage: #$0 [options] gemname
|
@@ -29,6 +31,31 @@ class CutAGemCommand
|
|
29
31
|
parser.on("-d", "--desc", "Describe this gem.") do |@description|
|
30
32
|
end
|
31
33
|
|
34
|
+
parser.on("-c", "--config", "Configure user values. Use #{ENV["EDITOR"]}") do |c|
|
35
|
+
@config.parent.mkpath
|
36
|
+
unless @config.exist?
|
37
|
+
@config.open("w") do |f|
|
38
|
+
f << <<-EOF.gsub(/^\t+/, "")
|
39
|
+
author: "#{ENV['USER']}"
|
40
|
+
email: "#{ENV['USER']}@#{ENV['HOST']}"
|
41
|
+
EOF
|
42
|
+
end
|
43
|
+
end
|
44
|
+
exec(ENV["EDITOR"], @config.to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
parser.on("--copy-template NAME", "Copy template to user template dir naming NAME") do |name|
|
48
|
+
@select = true
|
49
|
+
path = Pathname.new(ENV["HOME"]) + ".cutagem/templates" + name
|
50
|
+
if path.exist?
|
51
|
+
puts "#{path} is already exists."
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
template = select_template()
|
55
|
+
cp_r template, path, :verbose => true
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
|
32
59
|
parser.on("--version", "Show version string `#{VERSION}'") do
|
33
60
|
puts VERSION
|
34
61
|
exit
|
@@ -43,31 +70,6 @@ class CutAGemCommand
|
|
43
70
|
exit
|
44
71
|
end
|
45
72
|
|
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
73
|
pwd = Pathname.pwd
|
72
74
|
|
73
75
|
author = ENV['USER']
|
@@ -80,32 +82,7 @@ class CutAGemCommand
|
|
80
82
|
}.join("::")
|
81
83
|
description = @description
|
82
84
|
|
83
|
-
template =
|
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]
|
85
|
+
template = select_template()
|
109
86
|
|
110
87
|
gemdir = pwd + gemname
|
111
88
|
|
@@ -114,6 +91,13 @@ class CutAGemCommand
|
|
114
91
|
exit
|
115
92
|
end
|
116
93
|
|
94
|
+
begin
|
95
|
+
config = YAML.load(@config.read)
|
96
|
+
author = config["author"] if config["author"]
|
97
|
+
email = config["email"] if config["email"]
|
98
|
+
rescue Errno::ENOENT
|
99
|
+
end
|
100
|
+
|
117
101
|
begin
|
118
102
|
cp_r template, gemdir, :verbose => true
|
119
103
|
Pathname.glob(gemdir + "**/gemname*") do |f|
|
@@ -145,4 +129,57 @@ class CutAGemCommand
|
|
145
129
|
exec(ENV["EDITOR"], gemdir + "Rakefile")
|
146
130
|
end
|
147
131
|
end
|
132
|
+
|
133
|
+
def select_template
|
134
|
+
@templates = Pathname.new(File.dirname(__FILE__)).realpath + '../templates'
|
135
|
+
@user_templates = Pathname.new(ENV["HOME"]).realpath + '.cutagem/templates'
|
136
|
+
|
137
|
+
templates = []
|
138
|
+
u_templates = []
|
139
|
+
if @user_templates.exist?
|
140
|
+
Pathname.glob(@user_templates + "*").each do |t|
|
141
|
+
t = [".cutagem/templates/#{t.basename}", t]
|
142
|
+
if t[1].basename.to_s == "default"
|
143
|
+
u_templates.unshift(t)
|
144
|
+
else
|
145
|
+
u_templates << t
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
Pathname.glob(@templates + "*").each do |t|
|
150
|
+
t = ["#{t.basename}", t]
|
151
|
+
if t[1].basename.to_s == "default"
|
152
|
+
templates.unshift(t)
|
153
|
+
else
|
154
|
+
templates << t
|
155
|
+
end
|
156
|
+
end
|
157
|
+
templates = u_templates + templates
|
158
|
+
|
159
|
+
if @select
|
160
|
+
puts "Select template:"
|
161
|
+
templates.each_with_index do |item,index|
|
162
|
+
puts "% 2d. %s" % [index+1, item.first]
|
163
|
+
end
|
164
|
+
input = gets.chomp
|
165
|
+
case input
|
166
|
+
when ""
|
167
|
+
template = templates.first
|
168
|
+
when /^\d+$/
|
169
|
+
template = templates[input.to_i-1]
|
170
|
+
else
|
171
|
+
template = nil
|
172
|
+
puts "Canceled"
|
173
|
+
exit
|
174
|
+
end
|
175
|
+
else
|
176
|
+
template = templates.first
|
177
|
+
end
|
178
|
+
unless template
|
179
|
+
puts "Not select template."
|
180
|
+
exit
|
181
|
+
end
|
182
|
+
puts "Using Template: %s" % template
|
183
|
+
template[1]
|
184
|
+
end
|
148
185
|
end
|
File without changes
|
data/templates/command/Rakefile
CHANGED
@@ -44,7 +44,7 @@ spec = Gem::Specification.new do |s|
|
|
44
44
|
s.version = VERS
|
45
45
|
s.platform = Gem::Platform::RUBY
|
46
46
|
s.has_rdoc = true
|
47
|
-
s.extra_rdoc_files = ["README", "
|
47
|
+
s.extra_rdoc_files = ["README", "ChangeLog"]
|
48
48
|
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
49
49
|
s.summary = DESCRIPTION
|
50
50
|
s.description = DESCRIPTION
|
File without changes
|
data/templates/default/Rakefile
CHANGED
@@ -44,7 +44,7 @@ spec = Gem::Specification.new do |s|
|
|
44
44
|
s.version = VERS
|
45
45
|
s.platform = Gem::Platform::RUBY
|
46
46
|
s.has_rdoc = true
|
47
|
-
s.extra_rdoc_files = ["README", "
|
47
|
+
s.extra_rdoc_files = ["README", "ChangeLog"]
|
48
48
|
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
49
49
|
s.summary = DESCRIPTION
|
50
50
|
s.description = DESCRIPTION
|
data/test/cutagem_test.rb
CHANGED
@@ -2,94 +2,7 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
2
|
|
3
3
|
require "test/unit"
|
4
4
|
class SafeEvalTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
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)
|
5
|
+
def test_t
|
6
|
+
assert true
|
52
7
|
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
8
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: cutagem
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
6
|
+
version: 0.0.2
|
7
7
|
date: 2007-10-07 00:00:00 +09:00
|
8
8
|
summary: More safe eval codes.
|
9
9
|
require_paths:
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- templates/command
|
41
41
|
- templates/default
|
42
42
|
- templates/command/bin
|
43
|
-
- templates/command/
|
43
|
+
- templates/command/ChangeLog
|
44
44
|
- templates/command/lib
|
45
45
|
- templates/command/Rakefile
|
46
46
|
- templates/command/README
|
@@ -49,7 +49,7 @@ files:
|
|
49
49
|
- templates/command/test/gemname_test.rb
|
50
50
|
- templates/command/test/test_helper.rb
|
51
51
|
- templates/default/bin
|
52
|
-
- templates/default/
|
52
|
+
- templates/default/ChangeLog
|
53
53
|
- templates/default/lib
|
54
54
|
- templates/default/Rakefile
|
55
55
|
- templates/default/README
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- templates/default/lib/gempath.rb
|
58
58
|
- templates/default/test/gemname_test.rb
|
59
59
|
- templates/default/test/test_helper.rb
|
60
|
+
- ChangeLog
|
60
61
|
test_files:
|
61
62
|
- test/test_helper.rb
|
62
63
|
rdoc_options:
|
@@ -74,7 +75,7 @@ rdoc_options:
|
|
74
75
|
- "^(examples|extras)/"
|
75
76
|
extra_rdoc_files:
|
76
77
|
- README
|
77
|
-
-
|
78
|
+
- ChangeLog
|
78
79
|
executables:
|
79
80
|
- cutagem
|
80
81
|
extensions: []
|