Class: Rushmate::Command

Inherits:
Object
  • Object
show all
Includes:
TextmateHelper
Defined in:
lib/rushmate/command.rb

Overview

The Command Class is the main class in Rushmate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TextmateHelper

#current_line, #current_word, #project_directory, #project_directory?, #selected_text, #tm_directory, #tm_file, #tm_filename

Constructor Details

#initialize(&block) ⇒ Command

Class construction is designed to take a block that gets executed as part of the class

Example:

Rushmate::Command.new {
  exit.show_tool_tip project_directory['**/*.rb'].line_count
}


14
15
16
17
# File 'lib/rushmate/command.rb', line 14

def initialize(&block)
  setup_shell
  self.instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

anything not defined in Rushmate::Command should be defered to Rushmate::Command#execute



27
28
29
# File 'lib/rushmate/command.rb', line 27

def method_missing(sym, *args, &block)
  execute sym.to_s
end

Instance Attribute Details

#shellObject

Returns the value of attribute shell.



5
6
7
# File 'lib/rushmate/command.rb', line 5

def shell
  @shell
end

Instance Method Details

#execute(thing) ⇒ Object

execute the parameter against a Rush::Shell instance



20
21
22
23
# File 'lib/rushmate/command.rb', line 20

def execute(thing)
  shell.execute(thing)
  $last_res
end

#exitObject

return a reference to Rushmate::Exit This is useful for shortening up your code Example:

exit.show_tool_tip("nothing found")


36
37
38
# File 'lib/rushmate/command.rb', line 36

def exit
  Rushmate::Exit
end

#user_inputObject

return a reference to Rushmate::UserInput This is useful for shortening up your code Example:

user_input.quick_menu_from_array(['opt 1', 'opt 2'])


45
46
47
# File 'lib/rushmate/command.rb', line 45

def user_input
  Rushmate::UserInput
end