Class: Net::SSH::Xlogin::Template
- Inherits:
-
Object
- Object
- Net::SSH::Xlogin::Template
- Defined in:
- lib/net/ssh/xlogin/template.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
10- DEFAULT_PROMPT =
/[$%#>] ?\z/n
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#prompts ⇒ Object
readonly
Returns the value of attribute prompts.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #bind(name, &block) ⇒ Object
- #build(name, **opts) ⇒ Object
-
#initialize(name) ⇒ Template
constructor
A new instance of Template.
- #prompt(expect = nil, &block) ⇒ Object
- #prompt_patten ⇒ Object
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
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
9 10 11 |
# File 'lib/net/ssh/xlogin/template.rb', line 9 def methods @methods end |
#prompts ⇒ Object (readonly)
Returns the value of attribute prompts.
10 11 12 |
# File 'lib/net/ssh/xlogin/template.rb', line 10 def prompts @prompts end |
#timeout ⇒ Object (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_patten ⇒ Object
26 27 28 |
# File 'lib/net/ssh/xlogin/template.rb', line 26 def prompt_patten Regexp.union(prompt.map(&:first)) end |