Class: RubyShell::Chainer
- Inherits:
-
Object
- Object
- RubyShell::Chainer
show all
- Defined in:
- lib/rubyshell/chainer.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(command) ⇒ Chainer
Returns a new instance of Chainer.
7
8
9
|
# File 'lib/rubyshell/chainer.rb', line 7
def initialize(command)
@parts = [command]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/rubyshell/chainer.rb', line 21
def method_missing(method_name, *args, &block)
if method_name.start_with?(/[^A-Za-z0-9]/)
handle_chain(method_name, args.first)
else
super
end
end
|
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
5
6
7
|
# File 'lib/rubyshell/chainer.rb', line 5
def parts
@parts
end
|
Instance Method Details
#exec_commands ⇒ Object
33
34
35
|
# File 'lib/rubyshell/chainer.rb', line 33
def exec_commands
`#{to_shell}`.chomp
end
|
#handle_chain(operator, chainer) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/rubyshell/chainer.rb', line 11
def handle_chain(operator, chainer)
@parts = [
*@parts,
operator.to_s,
*(chainer.is_a?(RubyShell::Chainer) ? chainer.parts : chainer)
]
self
end
|
#respond_to_missing?(_name, _include_private) ⇒ Boolean
29
30
31
|
# File 'lib/rubyshell/chainer.rb', line 29
def respond_to_missing?(_name, _include_private)
false
end
|
#to_shell ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/rubyshell/chainer.rb', line 37
def to_shell
parts.map do |part|
if part.is_a?(RubyShell::Command)
part.to_shell
else
part
end
end.join(" ")
end
|