Class: Command::Runner::Backends::Fake Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/command/runner/backends/fake.rb

Overview

This class is abstract.

A fake backend. Used to a) define what backends should respond to, and b) provide default behavior for the backends.

Direct Known Subclasses

Backticks, SSH, Spawn, UnsafeFake

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFake

Initialize the fake backend.


42
43
44
45
46
# File 'lib/command/runner/backends/fake.rb', line 42

def initialize
  @ran = []

  raise NotAvailableBackendError unless self.class.available?
end

Class Method Details

.available?(force_unsafe = false) ⇒ Boolean

This method is abstract.

Returns whether or not this backend is avialable on this platform.


17
18
19
# File 'lib/command/runner/backends/fake.rb', line 17

def self.available?(force_unsafe = false)
  true
end

.unsafe?Boolean

A backend is considered unsafe when the arguments are exposed directly to the shell. This is a vulnerability, so we mark the class as unsafe and when we're about to pass the arguments to the backend, escape the safe interpolations.


28
29
30
# File 'lib/command/runner/backends/fake.rb', line 28

def self.unsafe?
  false
end

.unsafe_execution?Boolean

Whether or not it can handle unsafe execution. This is in case the developer wants to force unsafe execution on a safe backend.


37
38
39
# File 'lib/command/runner/backends/fake.rb', line 37

def self.unsafe_execution?
  true
end

Instance Method Details

#call(command, arguments, env = {}, options = {}) {|Message| ... } ⇒ Message, Object

This method is abstract.
Note:

Does nothing.

Run the given command and arguments, in the given environment.

Yields:

  • (Message)

    when the command finishes.

Raises:

  • (Errno::ENOENT)

    if the command doesn't exist.


62
63
64
65
66
67
# File 'lib/command/runner/backends/fake.rb', line 62

def call(command, arguments, env = {}, options = {}, &block)
  @ran << [command, arguments]

  message = Message.new :env => env, :options => options, :line =>
    [command, *arguments].join(' ')
end

#ran?(command, arguments) ⇒ Boolean

Determines whether or not the given command and arguments were ran with this backend.

See Also:


76
77
78
# File 'lib/command/runner/backends/fake.rb', line 76

def ran?(command, arguments)
  @ran.include?([command, *arguments])
end

#unsafe?Boolean


81
82
83
# File 'lib/command/runner/backends/fake.rb', line 81

def unsafe?
  self.class.unsafe?
end