Class: Nanite::Packet
Overview
Base class for all Nanite packets, knows how to dump itself to JSON
Direct Known Subclasses
Advertise, FileChunk, FileEnd, FileStart, Ping, Push, Register, Request, Result
Instance Method Summary collapse
-
#initialize ⇒ Packet
constructor
A new instance of Packet.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize ⇒ Packet
Returns a new instance of Packet.
5 6 7 |
# File 'lib/nanite/packets.rb', line 5 def initialize raise NotImplementedError.new("#{self.class.name} is an abstract class.") end |
Instance Method Details
#to_json(*a) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/nanite/packets.rb', line 8 def to_json(*a) { 'json_class' => self.class.name, 'data' => instance_variables.inject({}) {|m,ivar| m[ivar.sub(/@/,'')] = instance_variable_get(ivar); m } }.to_json(*a) end |