Class: Command::Runner::Backends::Fake Abstract
- Inherits:
-
Object
- Object
- Command::Runner::Backends::Fake
- Defined in:
- lib/command/runner/backends/fake.rb
Overview
A fake backend. Used to a) define what backends should respond to, and b) provide default behavior for the backends.
Direct Known Subclasses
Class Method Summary collapse
-
.available?(force_unsafe = false) ⇒ Boolean
abstract
Returns whether or not this backend is avialable on this platform.
-
.unsafe? ⇒ Boolean
A backend is considered unsafe when the arguments are exposed directly to the shell.
-
.unsafe_execution? ⇒ Boolean
Whether or not it can handle unsafe execution.
Instance Method Summary collapse
-
#call(command, arguments, env = {}, options = {}) {|Message| ... } ⇒ Message, Object
abstract
Run the given command and arguments, in the given environment.
-
#initialize ⇒ Fake
constructor
Initialize the fake backend.
-
#ran?(command, arguments) ⇒ Boolean
Determines whether or not the given command and arguments were ran with this backend.
- #unsafe? ⇒ Boolean
Constructor Details
#initialize ⇒ Fake
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
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
Does nothing.
Run the given command and arguments, in the given environment.
62 63 64 65 66 67 |
# File 'lib/command/runner/backends/fake.rb', line 62 def call(command, arguments, env = {}, = {}, &block) @ran << [command, arguments] = Message.new :env => env, :options => , :line => [command, *arguments].join(' ') end |
#ran?(command, arguments) ⇒ Boolean
Determines whether or not the given command and arguments were ran with this backend.
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 |