Class: Fancybox2::Logger::MQTTLogDevice
- Inherits:
-
Object
- Object
- Fancybox2::Logger::MQTTLogDevice
- Defined in:
- lib/fancybox2/logger/mqtt_log_device.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#topic ⇒ Object
Returns the value of attribute topic.
Instance Method Summary collapse
- #close(*args) ⇒ Object
-
#initialize(topic, *args) ⇒ MQTTLogDevice
constructor
A new instance of MQTTLogDevice.
- #write(message) ⇒ Object
Constructor Details
#initialize(topic, *args) ⇒ MQTTLogDevice
Returns a new instance of MQTTLogDevice.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fancybox2/logger/mqtt_log_device.rb', line 9 def initialize(topic, *args) @topic = topic = args..deep_symbolize_keys @client = [:client] unless @client.respond_to?(:publish) raise ArgumentError, "provided client does not respond to 'publish'" end unless @client.respond_to?(:connected?) raise ArgumentError, "provided client does not respond to 'connected?'" end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/fancybox2/logger/mqtt_log_device.rb', line 7 def client @client end |
#topic ⇒ Object
Returns the value of attribute topic.
7 8 9 |
# File 'lib/fancybox2/logger/mqtt_log_device.rb', line 7 def topic @topic end |
Instance Method Details
#close(*args) ⇒ Object
27 28 29 30 |
# File 'lib/fancybox2/logger/mqtt_log_device.rb', line 27 def close(*args) # Do nothing. # Future: close only if client is internal end |
#write(message) ⇒ Object
21 22 23 24 25 |
# File 'lib/fancybox2/logger/mqtt_log_device.rb', line 21 def write() if @client && @client.connected? @client.publish @topic, end end |