Class: TL1::Session
- Inherits:
-
Object
- Object
- TL1::Session
- Defined in:
- lib/tl1/session.rb
Overview
A wrapper around an IO-like object representing a connection to a TL1-capable network element.
Defined Under Namespace
Classes: WaitforWrapper
Instance Method Summary collapse
-
#cmd(command, **kwargs) ⇒ TL1::AST::Node
Execute a TL1::Command.
-
#expect(pattern, timeout = nil) ⇒ Object
Receive data until the given pattern is matched.
-
#initialize(io, timeout = 10) ⇒ Session
constructor
A new instance of Session.
-
#raw_cmd(message, timeout = nil) ⇒ String
Send a string and receive a string back.
-
#write(message) ⇒ Boolean
Send a string.
Constructor Details
#initialize(io, timeout = 10) ⇒ Session
Returns a new instance of Session.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tl1/session.rb', line 17 def initialize(io, timeout = 10) @timeout = timeout @io = if io.respond_to?(:expect) io elsif io.respond_to?(:waitfor) WaitforWrapper.new(io) else raise UnsupportedIOError, "the given IO doesn't respond to expect or waitfor" end end |
Instance Method Details
#cmd(command, **kwargs) ⇒ TL1::AST::Node
Execute a TL1::Command
34 35 36 37 |
# File 'lib/tl1/session.rb', line 34 def cmd(command, **kwargs) output = raw_cmd(command.input(**kwargs)) command.parse_output(output) end |
#expect(pattern, timeout = nil) ⇒ Object
Receive data until the given pattern is matched.
43 44 45 46 |
# File 'lib/tl1/session.rb', line 43 def expect(pattern, timeout = nil) timeout ||= @timeout @io.expect(pattern, timeout) end |
#raw_cmd(message, timeout = nil) ⇒ String
Send a string and receive a string back.
53 54 55 56 |
# File 'lib/tl1/session.rb', line 53 def raw_cmd(, timeout = nil) write() expect(COMPLD, timeout) end |
#write(message) ⇒ Boolean
Send a string.
62 63 64 |
# File 'lib/tl1/session.rb', line 62 def write() @io.write() end |