lib/reap/task.rb in reap-4.5.1 vs lib/reap/task.rb in reap-4.5.2

- old
+ new

@@ -60,11 +60,11 @@ def self.tasks unless @tasks @tasks = {} registry.each do |name, klass| - @tasks[name] = klass if klass.verify? + @tasks[name] = klass if klass.available? end end @tasks end @@ -77,75 +77,108 @@ RUBY = ::Config::CONFIG['ruby_install_name'] class << self - # When this class is inherited the new task is registered. - + # When this class is inherited the new task is registered + # by adding it to the task_list hash. def inherited( base ) task_list[base.task_name] = base end + # Task list hash. def task_list @task_list ||= {} end - # task dsl + # === Task DSL methods - def section_required( val ) ; @section_required = val ; end - def section_required? ; @section_required ; end + #def task_section_required( val ) ; @section_required = val ; end + #def section_required? ; @section_required ; end + # Provided the tasks name. This defualt's the task's + # class' name downcased, so it is rarely needed. def task_name basename.downcase end + # Short one-line description of the task. 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 + # Takes a string or a block the evaluates to a string + # providing detailed help information about the task. 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 + # Set alias for 'task' attribute, which provides + # inherited (from master) access to section data. def task_attr( name ) define_method(name) { @task } end - - def verify? - if section_required? - return ProjectInfo.instance.info.key?(task_name) + # How to determine if a task is available for use. + # By default a taks is only available if the Project + # file exists and the task's section also exists. + # Common was to loosen this resriction are to + # only require the file, not the seciton: + # + # task_available { Reap.projectfile? } + # + # Or have no restrictions: + # + # task_available true + # + def task_available( bool=false, &block ) + if bool + (class << self; self; end).class_eval { + define_method( :available? ){ true } + } + else + (class << self; self; end).class_eval { + define_method( :available?, &block ) + } end - true end + # Is the task available for use? By default + # a task is only made available if the ProjectInfo + # is present and the task's section is present. + def available? + return false unless Reap.projectfile? + #if section_required? + return has_section? + #end + #true + end + + # Project file exists and has task's section? + def has_section? + return false unless Reap.projectfile? + ProjectInfo.instance.info.key?( task_name ) + end + + # Class-level access to Project file's master data + # provided via a CascadingOpenObject. def master @master ||= ProjectInfo.instance.to_cascading_open_object - #@master ||= CascadingOpenObject.new( $PROJECT_INFO ) end - # properties not to be looked up in master - # if they are not in regular task section - -# def task_only_properties ; @task_only_properties ||= [] ; end -# def task_only_property( *names ) -# @task_only_properties ||= [] -# @task_only_properties |= names.collect { |n| n.to_s } -# end - end #<< class # instance methods def task_name ; self.class.task_name ; end def task_desc ; self.class.task_desc ; end def task_help ; self.class.task_help ; end - def section_required? ; self.class.section_required? ; end + #def section_required? ; self.class.section_required? ; end #def master ; ::ProjectInfo.info ; end def master ; self.class.master ; end def section ; @section ; end def task ; @task ; end