Class: Looksee::Editor
- Inherits:
-
Object
- Object
- Looksee::Editor
- Defined in:
- lib/looksee/editor.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
-
#command_for(file, line) ⇒ Object
Return the editor command for the given file and line.
-
#edit(object, method_name) ⇒ Object
Run the editor command for the
method_name
ofobject
. -
#initialize(command) ⇒ Editor
constructor
A new instance of Editor.
-
#run(file, line) ⇒ Object
Run the editor command for the given file and line.
Constructor Details
#initialize(command) ⇒ Editor
Returns a new instance of Editor.
5 6 7 8 |
# File 'lib/looksee/editor.rb', line 5 def initialize(command) @command = command.dup infer_arguments end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
10 11 12 |
# File 'lib/looksee/editor.rb', line 10 def command @command end |
Instance Method Details
#command_for(file, line) ⇒ Object
Return the editor command for the given file and line.
This is an array of the command with its arguments.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/looksee/editor.rb', line 34 def command_for(file, line) line = line.to_s words = Shellwords.shellwords(command) words.map! do |word| word.gsub!(/%f/, file) word.gsub!(/%l/, line) word.gsub!(/%%/, '%') word end end |
#edit(object, method_name) ⇒ Object
Run the editor command for the method_name
of object
.
15 16 17 18 19 20 |
# File 'lib/looksee/editor.rb', line 15 def edit(object, method_name) method = LookupPath.new(object).find(method_name.to_s) or return file, line = Looksee.adapter.source_location(method) run(file, line) unless line.nil? end |
#run(file, line) ⇒ Object
Run the editor command for the given file and line.
25 26 27 |
# File 'lib/looksee/editor.rb', line 25 def run(file, line) system *command_for(file, line) end |