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.

Parameters:

  • force_unsafe (Boolean) (defaults to: false)

    if the backend needs to be able to handle unsafe execution, then this will be true.

Returns:

  • (Boolean)

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.

Returns:

  • (Boolean)

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.

Returns:

  • (Boolean)

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.

Parameters:

  • command (String)

    the command to run.

  • arguments (String)

    the arguments to pass to the command.

  • env (Hash) (defaults to: {})

    the enviornment to run the command under.

  • options (Hash) (defaults to: {})

    the options to run the command under.

Yields:

  • (Message)

    when the command finishes.

Returns:

  • (Message, Object)

    message if no block is given, the result of the block call otherwise.

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.

Parameters:

  • command (String)
  • arguments (String)

Returns:

  • (Boolean)

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

Returns:

  • (Boolean)

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

def unsafe?
  self.class.unsafe?
end