Class: ADM::Message
- Inherits:
-
Object
- Object
- ADM::Message
- Defined in:
- lib/adm/message.rb
Instance Attribute Summary collapse
-
#compiled ⇒ Object
readonly
Returns the value of attribute compiled.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
- #hydra ⇒ Object
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(data = {}) ⇒ Message
constructor
A new instance of Message.
- #send_to(*tokens) ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Message
Returns a new instance of Message.
5 6 7 |
# File 'lib/adm/message.rb', line 5 def initialize data={} @data = data end |
Instance Attribute Details
#compiled ⇒ Object (readonly)
Returns the value of attribute compiled.
2 3 4 |
# File 'lib/adm/message.rb', line 2 def compiled @compiled end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
2 3 4 |
# File 'lib/adm/message.rb', line 2 def data @data end |
#hydra ⇒ Object
25 26 27 |
# File 'lib/adm/message.rb', line 25 def hydra @hydra ||= Typhoeus::Hydra.hydra end |
Instance Method Details
#compile ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/adm/message.rb', line 29 def compile @json ||= begin @compiled = true compiled_data = data.dup if compiled_data[:data] compiled_data[:data].each do |k,v| compiled_data[:data][k] = MultiJson.dump(compiled_data[:data][k]) end elsif compiled_data['data'] compiled_data['data'].each do |k,v| compiled_data['data'][k] = MultiJson.dump(compiled_data['data'][k]) end end MultiJson.dump(compiled_data) end end |
#send_to(*tokens) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/adm/message.rb', line 9 def send_to *tokens if tokens.first.is_a?(Array) tokens = tokens.first end notifications = tokens.collect do |token| note = ADM::Notification.new(token,self) note.queue(hydra) note end hydra.run notifications end |