Class: Reap::Task
- Inherits:
-
Object
show all
- Includes:
- FileUtils
- Defined in:
- lib/reap/task.rb
Direct Known Subclasses
Announce, Doap, ExTest, Info, Install, Manifest, Noop, Package, Perm, Publish, RDoc, Release, Test
Constant Summary
collapse
- RUBY =
::Config::CONFIG['ruby_install_name']
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Task
Returns a new instance of Task.
130
131
132
133
|
# File 'lib/reap/task.rb', line 130
def initialize( *args )
@args = args
end
|
Class Method Details
.inherited(base) ⇒ Object
When this class is inherited the new task is registered.
61
62
63
|
# File 'lib/reap/task.rb', line 61
def inherited( base )
task_list[base.task_name] = base
end
|
.master ⇒ Object
102
103
104
|
# File 'lib/reap/task.rb', line 102
def master
@master ||= CascadingOpenObject.new( $PROJECT_INFO )
end
|
.section_required(val) ⇒ Object
71
|
# File 'lib/reap/task.rb', line 71
def section_required( val ) ; @section_required = val ; end
|
.section_required? ⇒ Boolean
72
|
# File 'lib/reap/task.rb', line 72
def section_required? ; @section_required ; end
|
.task_attr(name) ⇒ Object
90
91
92
|
# File 'lib/reap/task.rb', line 90
def task_attr( name )
define_method(name) { @task }
end
|
.task_desc(text = nil, &block) ⇒ Object
78
79
80
81
82
|
# File 'lib/reap/task.rb', line 78
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
84
85
86
87
88
|
# File 'lib/reap/task.rb', line 84
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
65
66
67
|
# File 'lib/reap/task.rb', line 65
def task_list
@task_list ||= {}
end
|
.task_name ⇒ Object
74
75
76
|
# File 'lib/reap/task.rb', line 74
def task_name
basename.downcase
end
|
.verify? ⇒ Boolean
95
96
97
98
99
100
|
# File 'lib/reap/task.rb', line 95
def verify?
if section_required?
return $PROJECT_INFO.info.key?(task_name)
end
true
end
|
Instance Method Details
#ask(question, answers = nil) ⇒ Object
201
202
203
204
205
206
|
# File 'lib/reap/task.rb', line 201
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.
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/reap/task.rb', line 137
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.
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/reap/task.rb', line 151
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
126
|
# File 'lib/reap/task.rb', line 126
def master ; self.class.master ; end
|
#provide_setup_rb ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/reap/task.rb', line 212
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
182
183
184
|
# File 'lib/reap/task.rb', line 182
def run
raise "no action defined for task #{task_name}"
end
|
#section ⇒ Object
127
|
# File 'lib/reap/task.rb', line 127
def section ; @section ; end
|
#section_required? ⇒ Boolean
123
|
# File 'lib/reap/task.rb', line 123
def section_required? ; self.class.section_required? ; end
|
#sh(arg) ⇒ Object
196
197
198
199
|
# File 'lib/reap/task.rb', line 196
def sh( arg )
puts arg
system arg unless $PRETEND
end
|
#task ⇒ Object
128
|
# File 'lib/reap/task.rb', line 128
def task ; @task ; end
|
#task_desc ⇒ Object
120
|
# File 'lib/reap/task.rb', line 120
def task_desc ; self.class.task_desc ; end
|
#task_help ⇒ Object
121
|
# File 'lib/reap/task.rb', line 121
def task_help ; self.class.task_help ; end
|
#task_name ⇒ Object
119
|
# File 'lib/reap/task.rb', line 119
def task_name ; self.class.task_name ; end
|
#tell(statement) ⇒ Object
208
209
210
|
# File 'lib/reap/task.rb', line 208
def tell( statement )
puts statement
end
|
#use_subsection(name) ⇒ Object
188
189
190
191
192
193
194
|
# File 'lib/reap/task.rb', line 188
def use_subsection( name )
subsection = @section.__send__(name)
if subsection
subsection.__parent__ = @section
@task = subsection
end
end
|