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.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/looksee/editor.rb', line 40 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 21 22 23 24 25 26 |
# File 'lib/looksee/editor.rb', line 15 def edit(object, method_name) method = LookupPath.new(object).find(method_name.to_s) or raise NoMethodError, "no method `#{method_name}' in lookup path of #{object.class} instance" file, line = method.source_location if !file raise NoSourceLocationError, "no source location for #{method.owner}##{method.name}" elsif !File.exist?(file) raise NoSourceFileError, "cannot find source file: #{file}" else run(file, line) end end |
#run(file, line) ⇒ Object
Run the editor command for the given file and line.
31 32 33 |
# File 'lib/looksee/editor.rb', line 31 def run(file, line) system *command_for(file, line) end |