Class: RubyEdit::Grep
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(options) ⇒ Grep
constructor
A new instance of Grep.
- #search(output: $stdout, errors: $stderr) ⇒ Object
Methods inherited from Command
#command, #cursor, #editor, #exec_exist?, #execute, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(options) ⇒ Grep
Returns a new instance of Grep.
9 10 11 12 |
# File 'lib/ruby_edit/grep.rb', line 9 def initialize() @path = [:path] || '*' @expression = [:expression] end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/ruby_edit/grep.rb', line 7 def result @result end |
Instance Method Details
#search(output: $stdout, errors: $stderr) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_edit/grep.rb', line 14 def search(output: $stdout, errors: $stderr) if empty_expression? output.puts 'No expression given' return false end @result = run "grep -irn #{@path} -e '#{@expression}'" do |out, err| errors << err if err end rescue TTY::Command::ExitError => error output.puts error end |