Class: SSHake::Mock::Command
- Inherits:
-
Object
- Object
- SSHake::Mock::Command
- Defined in:
- lib/sshake/mock/command.rb
Instance Method Summary collapse
-
#initialize(matcher, &block) ⇒ Command
constructor
A new instance of Command.
- #make_response(environment) ⇒ Object
- #match(command) ⇒ Object
Constructor Details
#initialize(matcher, &block) ⇒ Command
Returns a new instance of Command.
9 10 11 12 |
# File 'lib/sshake/mock/command.rb', line 9 def initialize(matcher, &block) @matcher = matcher @block = block end |
Instance Method Details
#make_response(environment) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/sshake/mock/command.rb', line 26 def make_response(environment) response = SSHake::Response.new response.start_time = Time.now @block&.call(response, environment) response.finish_time = Time.now response end |
#match(command) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sshake/mock/command.rb', line 14 def match(command) command = command.to_s case @matcher when String @matcher == command ? [] : nil when Regexp if match = command.match(/\A#{@matcher}\z/) match.captures end end end |