Module: Quickl::Command::InstanceMethods

Defined in:
lib/quickl/command.rb

Overview

Methods installed on all command instances

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Delegate unrecognized calls to the command class (gives access to options, help, usage, …)



109
110
111
112
113
114
115
# File 'lib/quickl/command.rb', line 109

def method_missing(name, *args, &block)
  if self.class.respond_to?(name)
    self.class.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#requesterObject (readonly)

Who is requesting command execution?



105
106
107
# File 'lib/quickl/command.rb', line 105

def requester
  @requester
end

Instance Method Details

#handle_error(ex) ⇒ Object

Handles a command error



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/quickl/command.rb', line 118

def handle_error(ex)
  if react_to?(ex)
    begin
      ex.command = self
      ex.react!
    rescue Quickl::Error => ex2
      handle_error(ex2)
    end
  else
    raise ex
  end
end

#run(argv, requester = nil) ⇒ Object

Runs the command from a requester file with command-line arguments.

This method is intended to be overriden and does nothing by default.



138
139
140
141
142
143
# File 'lib/quickl/command.rb', line 138

def run(argv, requester = nil)
  @requester = requester
  _run(argv)
rescue Quickl::Error => ex
  handle_error(ex)
end