Class: Net::SSH::Xlogin::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/xlogin/template.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
10
DEFAULT_PROMPT =
/[$%#>] ?\z/n

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Template



13
14
15
16
17
18
# File 'lib/net/ssh/xlogin/template.rb', line 13

def initialize(name)
  @name    = name
  @prompts = Array.new
  @timeout = DEFAULT_TIMEOUT
  @methods = Hash.new
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



9
10
11
# File 'lib/net/ssh/xlogin/template.rb', line 9

def methods
  @methods
end

#promptsObject (readonly)

Returns the value of attribute prompts.



10
11
12
# File 'lib/net/ssh/xlogin/template.rb', line 10

def prompts
  @prompts
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



11
12
13
# File 'lib/net/ssh/xlogin/template.rb', line 11

def timeout
  @timeout
end

Instance Method Details

#bind(name, &block) ⇒ Object



30
31
32
# File 'lib/net/ssh/xlogin/template.rb', line 30

def bind(name, &block)
  @methods[name] = block
end

#build(name, **opts) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/net/ssh/xlogin/template.rb', line 34

def build(name, **opts)
  klass = Class.new(Net::SSH::Xlogin.const_get('Connection'))
  klass.class_exec(self) do |template|
    template.methods.each {|name, block| define_method(name, &block) }
  end
  klass.new(self, name, **opts)
end

#prompt(expect = nil, &block) ⇒ Object



20
21
22
23
24
# File 'lib/net/ssh/xlogin/template.rb', line 20

def prompt(expect = nil, &block)
  return [[DEFAULT_PROMPT, nil]] if expect.nil? && @prompts.empty?
  @prompts << [Regexp.new(expect.to_s), block] if expect
  @prompts
end

#prompt_pattenObject



26
27
28
# File 'lib/net/ssh/xlogin/template.rb', line 26

def prompt_patten
  Regexp.union(prompt.map(&:first))
end