Class: ShellB::Command
- Inherits:
-
Object
- Object
- ShellB::Command
- Defined in:
- lib/shellb/command.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#downstream ⇒ Object
Returns the value of attribute downstream.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Instance Method Summary collapse
- #<(from) ⇒ Object
- #>(to) ⇒ Object
- #>>(to) ⇒ Object
-
#initialize(shell, name, *opts) ⇒ Command
constructor
A new instance of Command.
- #pretty_print(pp) ⇒ Object
- #redirection_parts ⇒ Object
- #to_s ⇒ Object
- #to_sh ⇒ Object
- #|(command) ⇒ Object
Constructor Details
#initialize(shell, name, *opts) ⇒ Command
Returns a new instance of Command.
8 9 10 11 12 |
# File 'lib/shellb/command.rb', line 8 def initialize(shell, name, *opts) @shell = shell @name = name @opts = opts end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/shellb/command.rb', line 5 def block @block end |
#downstream ⇒ Object
Returns the value of attribute downstream.
6 7 8 |
# File 'lib/shellb/command.rb', line 6 def downstream @downstream end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/shellb/command.rb', line 5 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/shellb/command.rb', line 5 def opts @opts end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
5 6 7 |
# File 'lib/shellb/command.rb', line 5 def shell @shell end |
Instance Method Details
#<(from) ⇒ Object
29 30 31 32 |
# File 'lib/shellb/command.rb', line 29 def <(from) @input = from self end |
#>(to) ⇒ Object
19 20 21 22 |
# File 'lib/shellb/command.rb', line 19 def >(to) @output = to self end |
#>>(to) ⇒ Object
24 25 26 27 |
# File 'lib/shellb/command.rb', line 24 def >>(to) @append = to self end |
#pretty_print(pp) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/shellb/command.rb', line 57 def pretty_print(pp) pp.object_group(self) do pp.breakable pp.text "@name=" pp.pp @name pp.breakable pp.text "@opts=" pp.pp @opts end end |
#redirection_parts ⇒ Object
34 35 36 37 38 39 |
# File 'lib/shellb/command.rb', line 34 def redirection_parts return [">", @output.to_s] if @output return [">>", @append.to_s] if @append return ["<", @input.to_s] if @input return [] end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/shellb/command.rb', line 41 def to_s "<Command: #{name} #{opts.join(" ")}>" end |
#to_sh ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/shellb/command.rb', line 45 def to_sh parts = [] parts << Shellwords.shelljoin([name, *opts]) unless (rd_parts = redirection_parts.join(" ")).empty? parts.last << " " + rd_parts end parts << downstream.to_sh if downstream parts.join(" | ") end |
#|(command) ⇒ Object
14 15 16 17 |
# File 'lib/shellb/command.rb', line 14 def |(command) shell.drop_command(command) self.downstream = command end |