Class: LegoEv3::Connection
- Inherits:
-
Object
- Object
- LegoEv3::Connection
- Defined in:
- lib/connection/connection.rb
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(user_config = {}) ⇒ Connection
constructor
A new instance of Connection.
- #send(command, &callback) ⇒ Object
Constructor Details
#initialize(user_config = {}) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/connection/connection.rb', line 5 def initialize(user_config = {}) = { user_config: LegoEv3::default_user_config.merge(user_config) } OptionParser.new do |opt| opt.on('-c, --config PATH', 'Use the provided configuration at PATH.') do |path| [:user_config].merge!(LegoEv3::load_config(path)) end end.parse! is_local = `hostname`.strip == [:user_config]['ssh']['hostname'] @inner_connection = if is_local LegoEv3::LocalConnection.new else LegoEv3::RemoteConnection.new( [:user_config]['ssh']['host'], [:user_config]['ssh']['username'], [:user_config]['ssh']['password'] ) end end |
Instance Method Details
#close ⇒ Object
36 37 38 |
# File 'lib/connection/connection.rb', line 36 def close @inner_connection.close end |
#flush ⇒ Object
32 33 34 |
# File 'lib/connection/connection.rb', line 32 def flush @inner_connection.flush end |
#send(command, &callback) ⇒ Object
28 29 30 |
# File 'lib/connection/connection.rb', line 28 def send(command, &callback) @inner_connection.send(command, &callback) end |