Class: LMK::ShellCommand
- Inherits:
-
Object
- Object
- LMK::ShellCommand
- Defined in:
- lib/lmk/shell_command.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#html_url ⇒ Object
Returns the value of attribute html_url.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #concise_output ⇒ Object
- #concise_template ⇒ Object
- #full_output ⇒ Object
- #full_template ⇒ Object
- #get_binding ⇒ Object
-
#initialize(command) ⇒ ShellCommand
constructor
A new instance of ShellCommand.
- #output ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/lmk/shell_command.rb', line 6 def command @command end |
#html_url ⇒ Object
Returns the value of attribute html_url.
7 8 9 |
# File 'lib/lmk/shell_command.rb', line 7 def html_url @html_url end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/lmk/shell_command.rb', line 6 def @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_output ⇒ Object
42 43 44 |
# File 'lib/lmk/shell_command.rb', line 42 def concise_output concise_template.result get_binding end |
#concise_template ⇒ Object
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_output ⇒ Object
46 47 48 |
# File 'lib/lmk/shell_command.rb', line 46 def full_output full_template.result get_binding end |
#full_template ⇒ Object
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_binding ⇒ Object
18 19 20 |
# File 'lib/lmk/shell_command.rb', line 18 def get_binding binding end |
#output ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/lmk/shell_command.rb', line 34 def output if success? @output else @error end end |
#status ⇒ Object
30 31 32 |
# File 'lib/lmk/shell_command.rb', line 30 def status @status.exitstatus end |
#success? ⇒ Boolean
26 27 28 |
# File 'lib/lmk/shell_command.rb', line 26 def success? status == 0 end |