Class: Logcli::Actions::Grep

Inherits:
Object
  • Object
show all
Defined in:
lib/logcli/actions/grep.rb

Constant Summary collapse

COMMAND =
'grep'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Grep

Returns a new instance of Grep.



8
9
10
11
# File 'lib/logcli/actions/grep.rb', line 8

def initialize opts
  @grep = opts.fetch(:grep)
  @path = opts.fetch(:path)
end

Instance Attribute Details

#grepObject

Returns the value of attribute grep.



5
6
7
# File 'lib/logcli/actions/grep.rb', line 5

def grep
  @grep
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/logcli/actions/grep.rb', line 5

def path
  @path
end

#tmp_pathObject (readonly)

Returns the value of attribute tmp_path.



6
7
8
# File 'lib/logcli/actions/grep.rb', line 6

def tmp_path
  @tmp_path
end

Class Method Details

.call(opts) ⇒ Object



27
28
29
30
# File 'lib/logcli/actions/grep.rb', line 27

def self.call opts
  grep = new opts
  grep.call
end

Instance Method Details

#call(ssh) ⇒ Object



13
14
15
16
17
18
# File 'lib/logcli/actions/grep.rb', line 13

def call ssh
  cmd = "#{COMMAND} -rni \"#{grep}\" #{path} > #{tmp_path}"
  puts "[grep] start: [#{cmd}]"
  ssh.execute! cmd
  puts "[grep] finish: [#{cmd}]"
end