Class: OsCtl::Image::Operations::Nix::RunInShell
- Includes:
- Lib::Utils::Log, Lib::Utils::System
- Defined in:
- lib/osctl/image/operations/nix/run_in_shell.rb
Instance Attribute Summary collapse
- #command ⇒ Array<String> readonly
- #expression ⇒ String readonly
-
#name ⇒ Object
readonly
protected
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
protected
Returns the value of attribute opts.
Instance Method Summary collapse
- #create_executable ⇒ Object protected
- #execute ⇒ OsCtl::Lib::SystemCommandResult
-
#initialize(expression, command, opts = {}) ⇒ RunInShell
constructor
A new instance of RunInShell.
Methods inherited from Base
Constructor Details
#initialize(expression, command, opts = {}) ⇒ RunInShell
Returns a new instance of RunInShell.
21 22 23 24 25 26 27 |
# File 'lib/osctl/image/operations/nix/run_in_shell.rb', line 21 def initialize(expression, command, opts = {}) super() @expression = expression @command = command @name = opts.delete(:name) || 'nix-shell-run' @opts = opts end |
Instance Attribute Details
#command ⇒ Array<String> (readonly)
13 14 15 |
# File 'lib/osctl/image/operations/nix/run_in_shell.rb', line 13 def command @command end |
#expression ⇒ String (readonly)
10 11 12 |
# File 'lib/osctl/image/operations/nix/run_in_shell.rb', line 10 def expression @expression end |
#name ⇒ Object (readonly, protected)
Returns the value of attribute name.
40 41 42 |
# File 'lib/osctl/image/operations/nix/run_in_shell.rb', line 40 def name @name end |
#opts ⇒ Object (readonly, protected)
Returns the value of attribute opts.
40 41 42 |
# File 'lib/osctl/image/operations/nix/run_in_shell.rb', line 40 def opts @opts end |
Instance Method Details
#create_executable ⇒ Object (protected)
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/osctl/image/operations/nix/run_in_shell.rb', line 42 def create_executable tmp = Tempfile.new(name, '/tmp') tmp.write(<<~EOF #!/bin/sh exec #{command.join(' ')} EOF ) tmp.close File.chmod(0o700, tmp.path) tmp end |
#execute ⇒ OsCtl::Lib::SystemCommandResult
31 32 33 34 35 36 |
# File 'lib/osctl/image/operations/nix/run_in_shell.rb', line 31 def execute exe = create_executable syscmd("nix-shell --run #{exe.path} #{expression}", opts) ensure exe.unlink end |