Class: Reap::Task
- Inherits:
-
Object
show all
- Includes:
- FileUtils
- Defined in:
- lib/reap/task.rb
Overview
Direct Known Subclasses
Announce, Doap, ExTest, Info, Install, Manifest, Package, Perm, Publish, RDoc, Release, Test
Constant Summary
collapse
- RUBY =
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Task
Returns a new instance of Task.
154
155
156
157
|
# File 'lib/reap/task.rb', line 154
def initialize( *args )
@args = args
end
|
Class Method Details
.inherited(base) ⇒ Object
When this class is inherited the new task is registered.
84
85
86
|
# File 'lib/reap/task.rb', line 84
def inherited( base )
task_list[base.task_name] = base
end
|
.master ⇒ Object
125
126
127
128
|
# File 'lib/reap/task.rb', line 125
def master
@master ||= ProjectInfo.instance.to_cascading_open_object
end
|
.section_required(val) ⇒ Object
94
|
# File 'lib/reap/task.rb', line 94
def section_required( val ) ; @section_required = val ; end
|
.section_required? ⇒ Boolean
95
|
# File 'lib/reap/task.rb', line 95
def section_required? ; @section_required ; end
|
.task_attr(name) ⇒ Object
113
114
115
|
# File 'lib/reap/task.rb', line 113
def task_attr( name )
define_method(name) { @task }
end
|
.task_desc(text = nil, &block) ⇒ Object
101
102
103
104
105
|
# File 'lib/reap/task.rb', line 101
def task_desc( text=nil, &block )
return @task_desc = proc { text } if text
return @task_desc = block if block_given?
return @task_desc.call
end
|
.task_help(text = nil, &block) ⇒ Object
107
108
109
110
111
|
# File 'lib/reap/task.rb', line 107
def task_help( text=nil, &block )
return @task_help = proc { text } if text
return @task_help = block if block_given?
return @task_help.call
end
|
.task_list ⇒ Object
88
89
90
|
# File 'lib/reap/task.rb', line 88
def task_list
@task_list ||= {}
end
|
.task_name ⇒ Object
97
98
99
|
# File 'lib/reap/task.rb', line 97
def task_name
basename.downcase
end
|
.verify? ⇒ Boolean
118
119
120
121
122
123
|
# File 'lib/reap/task.rb', line 118
def verify?
if section_required?
return ProjectInfo.instance.info.key?(task_name)
end
true
end
|
Instance Method Details
#ask(question, answers = nil) ⇒ Object
225
226
227
228
229
230
|
# File 'lib/reap/task.rb', line 225
def ask( question, answers=nil )
print "#{question}"
print " [#{answers}] " if answers
until inp = $stdin.gets[0,1] ; sleep 1 ; end ; puts
inp
end
|
#execute(section = nil) ⇒ Object
Run task for each section entires given.
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/reap/task.rb', line 161
def execute( section=nil )
section = section || master[task_name]
case section
when Array
section.each do |s|
initiate( s )
end
else
initiate( section )
end
end
|
#initiate(section) ⇒ Object
Per section entry execution of task.
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/reap/task.rb', line 175
def initiate( section )
@section = CascadingOpenObject.new( section )
task_properties = {} task_properties = CascadingOpenObject.new( section )
task_properties.__parent__ = master
@task = task_properties
if respond_to?( :init )
if method(:init).arity == 0
init
else
init( *@args )
end
end
if method(:run).arity == 0
run
else
run( *@args )
end
end
|
#master ⇒ Object
def master ; ::ProjectInfo.info ; end
150
|
# File 'lib/reap/task.rb', line 150
def master ; self.class.master ; end
|
#provide_setup_rb ⇒ Object
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/reap/task.rb', line 236
def provide_setup_rb
return true if File.exists?( 'setup.rb')
f = File.join( Config::CONFIG['datadir'], 'reap', 'setup_rb', 'setup.rb' )
if File.exists?(f)
File.cp( f, '.' )
true
else
nil
end
end
|
#run ⇒ Object
def init
raise "not implemented for '#{task_name}' task"
end
206
207
208
|
# File 'lib/reap/task.rb', line 206
def run
raise "no action defined for task #{task_name}"
end
|
#section ⇒ Object
151
|
# File 'lib/reap/task.rb', line 151
def section ; @section ; end
|
#section_required? ⇒ Boolean
147
|
# File 'lib/reap/task.rb', line 147
def section_required? ; self.class.section_required? ; end
|
#sh(arg) ⇒ Object
220
221
222
223
|
# File 'lib/reap/task.rb', line 220
def sh( arg )
puts arg
system arg unless $PRETEND
end
|
#task ⇒ Object
152
|
# File 'lib/reap/task.rb', line 152
def task ; @task ; end
|
#task_desc ⇒ Object
144
|
# File 'lib/reap/task.rb', line 144
def task_desc ; self.class.task_desc ; end
|
#task_help ⇒ Object
145
|
# File 'lib/reap/task.rb', line 145
def task_help ; self.class.task_help ; end
|
#task_name ⇒ Object
143
|
# File 'lib/reap/task.rb', line 143
def task_name ; self.class.task_name ; end
|
#tell(statement) ⇒ Object
232
233
234
|
# File 'lib/reap/task.rb', line 232
def tell( statement )
puts statement
end
|
#use_subsection(name) ⇒ Object
212
213
214
215
216
217
218
|
# File 'lib/reap/task.rb', line 212
def use_subsection( name )
subsection = @section.__send__(name)
if subsection
subsection.__parent__ = @section
@task = subsection
end
end
|