Class: Caty::Task

Inherits:
Object
  • Object
show all
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

Attributes included from HasDescription

#description

Instance Method Summary collapse

Methods included from HasDescription

#short_description

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, options )
    @name, @instance_method, @options =
        name, instance_method, options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/caty/task.rb', line 16

def name
  @name
end

#usageObject

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_helpObject

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_sObject



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