ThiagoLelis-backgroundjob 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,12 @@
1
- module Main
2
- module Softspoken
3
- class << self
4
- fattr 'softspoken' => true
5
- def on!() softspoken(true) end
6
- def off!() softspoken(false) end
7
- def === other
8
- softspoken ? super : false
9
- end
10
- end
11
- end
12
- end
1
+ module Main
2
+ module Softspoken
3
+ class << self
4
+ fattr 'softspoken' => true
5
+ def on!() softspoken(true) end
6
+ def off!() softspoken(false) end
7
+ def === other
8
+ softspoken ? super : false
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/main/stdext.rb CHANGED
@@ -1,38 +1,38 @@
1
- class Object
2
- def singleton_class object = self, &block
3
- sc =
4
- class << object
5
- self
6
- end
7
- block ? sc.module_eval(&block) : sc
8
- end
9
-
10
- end
11
-
12
- module SaneAbort
13
- def abort message = nil
14
- if message
15
- message = message.to_s
16
- message.singleton_class{ fattr 'abort' => true }
17
- STDERR.puts message
18
- end
19
- exit 1
20
- end
21
- end
22
-
23
- def abort message = nil
24
- if message
25
- message = message.to_s
26
- message.singleton_class{ fattr 'abort' => true }
27
- STDERR.puts message
28
- end
29
- exit 1
30
- end
31
- def Process.abort message = nil
32
- if message
33
- message = message.to_s
34
- message.singleton_class{ fattr 'abort' => true }
35
- STDERR.puts message
36
- end
37
- exit 1
38
- end
1
+ class Object
2
+ def singleton_class object = self, &block
3
+ sc =
4
+ class << object
5
+ self
6
+ end
7
+ block ? sc.module_eval(&block) : sc
8
+ end
9
+
10
+ end
11
+
12
+ module SaneAbort
13
+ def abort message = nil
14
+ if message
15
+ message = message.to_s
16
+ message.singleton_class{ fattr 'abort' => true }
17
+ STDERR.puts message
18
+ end
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ def abort message = nil
24
+ if message
25
+ message = message.to_s
26
+ message.singleton_class{ fattr 'abort' => true }
27
+ STDERR.puts message
28
+ end
29
+ exit 1
30
+ end
31
+ def Process.abort message = nil
32
+ if message
33
+ message = message.to_s
34
+ message.singleton_class{ fattr 'abort' => true }
35
+ STDERR.puts message
36
+ end
37
+ exit 1
38
+ end
data/lib/main/usage.rb CHANGED
@@ -1,211 +1,211 @@
1
- module Main
2
- class Usage < ::Array
3
- fattr 'chunkname'
4
- fattr 'upcase'
5
- fattr 'eos'
6
-
7
- def initialize opts={}
8
- self.fields=[]
9
- self.chunkname = lambda{|chunkname| chunkname.to_s.strip.upcase}
10
- self.upcase = true
11
- self.eos = "\n\n"
12
- if opts.has_key?(:upcase) or opts.has_key?('upcase')
13
- self.upcase = opts[:upcase] || opts['optcase']
14
- end
15
- end
16
-
17
- def clear
18
- super
19
- ensure
20
- fields.clear
21
- end
22
-
23
- def delete_at key
24
- self[key] = nil
25
- end
26
- alias_method 'delete', 'delete_at'
27
-
28
- def self.default_synopsis main
29
- # build up synopsis
30
- s = "#{ main.name }"
31
-
32
- # mode info
33
- if main.mode_name != 'main'
34
- s << " #{ main.fully_qualified_mode.join ' ' }"
35
- end
36
-
37
- unless main.modes.empty?
38
- modes = main.modes.keys.join('|')
39
- s << " (#{ modes })"
40
- end
41
-
42
- # argument info
43
- main.parameters.each do |p|
44
- if p.type == :argument
45
- if(p.required? and p.arity != -1)
46
- if p.arity > 0
47
- p.arity.times{ s << " #{ p.name }" }
48
- else
49
- (p.arity.abs - 1).times{ s << " #{ p.name }" }
50
- s << " #{ p.name }*"
51
- end
52
- else
53
- #s << " [#{ p.name }]"
54
- if p.arity > 0
55
- a = []
56
- p.arity.times{ a << "#{ p.name }" }
57
- s << " [#{ a.join ' ' }]"
58
- else
59
- a = []
60
- (p.arity.abs - 1).times{ a << "#{ p.name }" }
61
- a << "#{ p.name }*"
62
- s << " [#{ a.join ' ' }]"
63
- end
64
- end
65
- end
66
- end
67
-
68
- # keyword info
69
- main.parameters.each do |p|
70
- if p.type == :keyword
71
- if p.required?
72
- s << " #{ p.name }=#{ p.name }"
73
- else
74
- s << " [#{ p.name }=#{ p.name }]"
75
- end
76
- end
77
- end
78
-
79
- # option info
80
- n = 0
81
- main.parameters.each do |p|
82
- if p.type == :option
83
- if p.required?
84
- case p.argument
85
- when :required
86
- s << " --#{ p.name }=#{ p.name }"
87
- when :optional
88
- s << " --#{ p.name }=[#{ p.name }]"
89
- else
90
- s << " --#{ p.name }"
91
- end
92
- else
93
- n += 1
94
- end
95
- end
96
- end
97
- if n > 0
98
- s << " [options]+"
99
- end
100
-
101
- # help info
102
- =begin
103
- if main.modes.size > 0
104
- modes = main.modes.keys.join('|')
105
- s << "\n#{ main.name } (#{ modes }) help"
106
- end
107
- if main.mode_name != 'main'
108
- s << "\n#{ main.name } #{ main.fully_qualified_mode.join ' ' } help"
109
- else
110
- s << "\n#{ main.name } help"
111
- end
112
- =end
113
-
114
- s
115
- end
116
-
117
- def name_section
118
- if main.version?
119
- "#{ main.name } v#{ main.version }"
120
- else
121
- "#{ main.name }"
122
- end
123
- end
124
-
125
- def synopsis_section
126
- main.synopsis
127
- end
128
-
129
- def description_section
130
- main.description if main.description?
131
- end
132
-
133
- def parameters_section
134
- arguments = main.parameters.select{|p| p.type == :argument}
135
- keywords = main.parameters.select{|p| p.type == :keyword}
136
- options = main.parameters.select{|p| p.type == :option}
137
- environment = main.parameters.select{|p| p.type == :environment}
138
-
139
- help, nothelp = options.partition{|p| p.name == 'help'}
140
- options = nothelp + help
141
-
142
- parameters = arguments + keywords + options + environment
143
-
144
- s =
145
- parameters.map do |p|
146
- ps = ''
147
- ps << Util.columnize("#{ p.synopsis }", :indent => 2, :width => 78)
148
- #ps << Util.columnize("* #{ p.synopsis }", :indent => 2, :width => 78)
149
- #ps << "\n"
150
- if p.description?
151
- ps << "\n"
152
- ps << Util.columnize("#{ p.description }", :indent => 6, :width => 78)
153
- #ps << Util.columnize(p.description, :indent => 6, :width => 78)
154
- #ps << "\n"
155
- end
156
- #ps << "\n"
157
- unless(p.examples.nil? or p.examples.empty?)
158
- p.examples.each do |example|
159
- ps << "\n"
160
- ps << Util.columnize("#{ example }", :indent => 8, :width => 78)
161
- end
162
- end
163
- ps
164
- end.join("\n")
165
- end
166
-
167
- def author_section
168
- main.author
169
- end
170
-
171
- class << self
172
- def default_usage main
173
- usage = new
174
- usage.main = main
175
- # HACK
176
- %w( name synopsis description parameters author ).each do |key|
177
- usage[key] = nil
178
- end
179
- usage
180
- end
181
-
182
- alias_method "default", "default_usage"
183
- end
184
-
185
- fattr "main"
186
-
187
- def set_defaults!
188
- usage = self
189
- usage['name'] ||= name_section
190
- usage['synopsis'] ||= synopsis_section
191
- usage['description'] ||= description_section
192
- usage['parameters'] ||= parameters_section unless main.parameters.empty?
193
- usage['author'] ||= author_section if main.author?
194
- end
195
-
196
- def to_s
197
- set_defaults!
198
- s = ''
199
- each_pair do |key, value|
200
- next unless(key and value)
201
- up, down = key.to_s.upcase, key.to_s.downcase
202
- if value
203
- s << (upcase ? up : down) << "\n"
204
- s << Util.indent(Util.unindent(value.to_s), 2)
205
- s << eos
206
- end
207
- end
208
- s
209
- end
210
- end
211
- end
1
+ module Main
2
+ class Usage < ::Array
3
+ fattr 'chunkname'
4
+ fattr 'upcase'
5
+ fattr 'eos'
6
+
7
+ def initialize opts={}
8
+ self.fields=[]
9
+ self.chunkname = lambda{|chunkname| chunkname.to_s.strip.upcase}
10
+ self.upcase = true
11
+ self.eos = "\n\n"
12
+ if opts.has_key?(:upcase) or opts.has_key?('upcase')
13
+ self.upcase = opts[:upcase] || opts['optcase']
14
+ end
15
+ end
16
+
17
+ def clear
18
+ super
19
+ ensure
20
+ fields.clear
21
+ end
22
+
23
+ def delete_at key
24
+ self[key] = nil
25
+ end
26
+ alias_method 'delete', 'delete_at'
27
+
28
+ def self.default_synopsis main
29
+ # build up synopsis
30
+ s = "#{ main.name }"
31
+
32
+ # mode info
33
+ if main.mode_name != 'main'
34
+ s << " #{ main.fully_qualified_mode.join ' ' }"
35
+ end
36
+
37
+ unless main.modes.empty?
38
+ modes = main.modes.keys.join('|')
39
+ s << " (#{ modes })"
40
+ end
41
+
42
+ # argument info
43
+ main.parameters.each do |p|
44
+ if p.type == :argument
45
+ if(p.required? and p.arity != -1)
46
+ if p.arity > 0
47
+ p.arity.times{ s << " #{ p.name }" }
48
+ else
49
+ (p.arity.abs - 1).times{ s << " #{ p.name }" }
50
+ s << " #{ p.name }*"
51
+ end
52
+ else
53
+ #s << " [#{ p.name }]"
54
+ if p.arity > 0
55
+ a = []
56
+ p.arity.times{ a << "#{ p.name }" }
57
+ s << " [#{ a.join ' ' }]"
58
+ else
59
+ a = []
60
+ (p.arity.abs - 1).times{ a << "#{ p.name }" }
61
+ a << "#{ p.name }*"
62
+ s << " [#{ a.join ' ' }]"
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ # keyword info
69
+ main.parameters.each do |p|
70
+ if p.type == :keyword
71
+ if p.required?
72
+ s << " #{ p.name }=#{ p.name }"
73
+ else
74
+ s << " [#{ p.name }=#{ p.name }]"
75
+ end
76
+ end
77
+ end
78
+
79
+ # option info
80
+ n = 0
81
+ main.parameters.each do |p|
82
+ if p.type == :option
83
+ if p.required?
84
+ case p.argument
85
+ when :required
86
+ s << " --#{ p.name }=#{ p.name }"
87
+ when :optional
88
+ s << " --#{ p.name }=[#{ p.name }]"
89
+ else
90
+ s << " --#{ p.name }"
91
+ end
92
+ else
93
+ n += 1
94
+ end
95
+ end
96
+ end
97
+ if n > 0
98
+ s << " [options]+"
99
+ end
100
+
101
+ # help info
102
+ =begin
103
+ if main.modes.size > 0
104
+ modes = main.modes.keys.join('|')
105
+ s << "\n#{ main.name } (#{ modes }) help"
106
+ end
107
+ if main.mode_name != 'main'
108
+ s << "\n#{ main.name } #{ main.fully_qualified_mode.join ' ' } help"
109
+ else
110
+ s << "\n#{ main.name } help"
111
+ end
112
+ =end
113
+
114
+ s
115
+ end
116
+
117
+ def name_section
118
+ if main.version?
119
+ "#{ main.name } v#{ main.version }"
120
+ else
121
+ "#{ main.name }"
122
+ end
123
+ end
124
+
125
+ def synopsis_section
126
+ main.synopsis
127
+ end
128
+
129
+ def description_section
130
+ main.description if main.description?
131
+ end
132
+
133
+ def parameters_section
134
+ arguments = main.parameters.select{|p| p.type == :argument}
135
+ keywords = main.parameters.select{|p| p.type == :keyword}
136
+ options = main.parameters.select{|p| p.type == :option}
137
+ environment = main.parameters.select{|p| p.type == :environment}
138
+
139
+ help, nothelp = options.partition{|p| p.name == 'help'}
140
+ options = nothelp + help
141
+
142
+ parameters = arguments + keywords + options + environment
143
+
144
+ s =
145
+ parameters.map do |p|
146
+ ps = ''
147
+ ps << Util.columnize("#{ p.synopsis }", :indent => 2, :width => 78)
148
+ #ps << Util.columnize("* #{ p.synopsis }", :indent => 2, :width => 78)
149
+ #ps << "\n"
150
+ if p.description?
151
+ ps << "\n"
152
+ ps << Util.columnize("#{ p.description }", :indent => 6, :width => 78)
153
+ #ps << Util.columnize(p.description, :indent => 6, :width => 78)
154
+ #ps << "\n"
155
+ end
156
+ #ps << "\n"
157
+ unless(p.examples.nil? or p.examples.empty?)
158
+ p.examples.each do |example|
159
+ ps << "\n"
160
+ ps << Util.columnize("#{ example }", :indent => 8, :width => 78)
161
+ end
162
+ end
163
+ ps
164
+ end.join("\n")
165
+ end
166
+
167
+ def author_section
168
+ main.author
169
+ end
170
+
171
+ class << self
172
+ def default_usage main
173
+ usage = new
174
+ usage.main = main
175
+ # HACK
176
+ %w( name synopsis description parameters author ).each do |key|
177
+ usage[key] = nil
178
+ end
179
+ usage
180
+ end
181
+
182
+ alias_method "default", "default_usage"
183
+ end
184
+
185
+ fattr "main"
186
+
187
+ def set_defaults!
188
+ usage = self
189
+ usage['name'] ||= name_section
190
+ usage['synopsis'] ||= synopsis_section
191
+ usage['description'] ||= description_section
192
+ usage['parameters'] ||= parameters_section unless main.parameters.empty?
193
+ usage['author'] ||= author_section if main.author?
194
+ end
195
+
196
+ def to_s
197
+ set_defaults!
198
+ s = ''
199
+ each_pair do |key, value|
200
+ next unless(key and value)
201
+ up, down = key.to_s.upcase, key.to_s.downcase
202
+ if value
203
+ s << (upcase ? up : down) << "\n"
204
+ s << Util.indent(Util.unindent(value.to_s), 2)
205
+ s << eos
206
+ end
207
+ end
208
+ s
209
+ end
210
+ end
211
+ end