Class: Caty::Task
- Inherits:
-
Object
- Object
- Caty::Task
- Includes:
- HasDescription, Helpers
- Defined in:
- lib/caty/task.rb
Overview
Represents a single task.
A Task object is created for every public method created in the Caty subclass.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#usage ⇒ Object
Returns the value of attribute usage.
Attributes included from HasDescription
Instance Method Summary collapse
-
#execute(context) ⇒ Object
Executes the associated instance_method by binding it to the given context.
-
#initialize(name, instance_method, options) ⇒ Task
constructor
Creates a new task with the given name for the given instance_method.
-
#parse!(args) ⇒ Object
Tries to remove the options defined for this task from the args array.
-
#resolve(task_hash) ⇒ Object
Resolving end point.
-
#to_help ⇒ Object
Returns a string representation of the task and its options to be used by the help system.
- #to_s ⇒ Object
Methods included from HasDescription
Constructor Details
#initialize(name, instance_method, options) ⇒ Task
Creates a new task with the given name for the given instance_method.
22 23 24 25 |
# File 'lib/caty/task.rb', line 22 def initialize( name, instance_method, ) @name, @instance_method, @options = name, instance_method, end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/caty/task.rb', line 16 def name @name end |
#usage ⇒ Object
Returns the value of attribute usage.
16 17 18 |
# File 'lib/caty/task.rb', line 16 def usage @usage end |
Instance Method Details
#execute(context) ⇒ Object
Executes the associated instance_method by binding it to the given context.
43 44 45 |
# File 'lib/caty/task.rb', line 43 def execute( context ) @instance_method.bind(context).call(*@args) end |
#parse!(args) ⇒ Object
Tries to remove the options defined for this task from the args array.
Returns an OpenHash containing the retrieved options.
34 35 36 37 |
# File 'lib/caty/task.rb', line 34 def parse!( args ) @args = args @options.grep!(args) end |
#resolve(task_hash) ⇒ Object
Resolving end point. See Caty::Indirection#resolve() for more information.
51 52 53 |
# File 'lib/caty/task.rb', line 51 def resolve( task_hash ) self end |
#to_help ⇒ Object
Returns a string representation of the task and its options to be used by the help system.
59 60 61 |
# File 'lib/caty/task.rb', line 59 def to_help [ self.to_s , self.short_description, self.description ] end |
#to_s ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/caty/task.rb', line 63 def to_s returning(@name.to_s) do |output| output << " #{@usage}" unless @usage.nil? @options.each do |option| output << " #{option}" end end end |