Class: SSHake::Mock::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/sshake/mock/command.rb

Instance Method Summary collapse

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