Class: LMK::ShellCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/lmk/shell_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ ShellCommand

Returns a new instance of ShellCommand.



9
10
11
12
13
14
15
16
# File 'lib/lmk/shell_command.rb', line 9

def initialize(command)
  @timestamp = Time.now
  @command = command
  @status = ::POpen4.popen4(command) do |stdout, stderr, stdin, pid| 
    @error = stderr.read 
    @output = stdout.read
  end
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/lmk/shell_command.rb', line 6

def command
  @command
end

#html_urlObject

Returns the value of attribute html_url.



7
8
9
# File 'lib/lmk/shell_command.rb', line 7

def html_url
  @html_url
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/lmk/shell_command.rb', line 6

def timestamp
  @timestamp
end

Class Method Details

.exec(command) ⇒ Object



22
23
24
# File 'lib/lmk/shell_command.rb', line 22

def self.exec(command)
  new(command)
end

Instance Method Details

#concise_outputObject



42
43
44
# File 'lib/lmk/shell_command.rb', line 42

def concise_output
  concise_template.result get_binding
end

#concise_templateObject



62
63
64
65
66
67
68
# File 'lib/lmk/shell_command.rb', line 62

def concise_template
  ERB.new %q{LMK Command Result:
> <%=command%>
<% if success? %>succeeded 
<% else %>failed (<%=status%>)<% end %>
<% if html_url %>full result @ <%= html_url %><% end %>}
end

#full_outputObject



46
47
48
# File 'lib/lmk/shell_command.rb', line 46

def full_output
  full_template.result get_binding
end

#full_templateObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/lmk/shell_command.rb', line 50

def full_template
  ERB.new %q{
%%% LMK Command Result: %%%
> <%= command %>
<% if success? %>succeeded 
<% else %> failed (<%=status%>)<% end %>
full output:
----------------------------
<%=output%>
  }
end

#get_bindingObject



18
19
20
# File 'lib/lmk/shell_command.rb', line 18

def get_binding
  binding
end

#outputObject



34
35
36
37
38
39
40
# File 'lib/lmk/shell_command.rb', line 34

def output
  if success?
    @output
  else
    @error
  end
end

#statusObject



30
31
32
# File 'lib/lmk/shell_command.rb', line 30

def status
  @status.exitstatus
end

#success?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/lmk/shell_command.rb', line 26

def success?
  status == 0
end