Class: Axon::AxonMsg
- Inherits:
-
Object
show all
- Defined in:
- lib/axon-nats/msg.rb
Constant Summary
collapse
- KEY_ERROR =
"_error"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data = {}, error = nil) ⇒ AxonMsg
Returns a new instance of AxonMsg.
10
11
12
13
14
|
# File 'lib/axon-nats/msg.rb', line 10
def initialize(data = {}, error = nil)
raise "data must be a hash" unless data.is_a? Hash
@data = data
@data[KEY_ERROR] = error unless error.nil?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
30
31
32
|
# File 'lib/axon-nats/msg.rb', line 30
def method_missing(method, *args)
@data.send(method, *args) if @data.respond_to? method
end
|
Class Method Details
.parse(msg_s) ⇒ Object
6
7
8
9
|
# File 'lib/axon-nats/msg.rb', line 6
def self.parse(msg_s)
msg_o = JSON.parse(msg_s)
AxonMsg.new(msg_o, msg_o[KEY_ERROR])
end
|
Instance Method Details
#[](key) ⇒ Object
15
16
17
|
# File 'lib/axon-nats/msg.rb', line 15
def [](key)
@data[key.to_s]
end
|
#[]=(key, value) ⇒ Object
18
19
20
|
# File 'lib/axon-nats/msg.rb', line 18
def []=(key, value)
@data[key.to_s] = value
end
|
#error? ⇒ Boolean
21
22
23
|
# File 'lib/axon-nats/msg.rb', line 21
def error?
!@data[KEY_ERROR].nil?
end
|
#to_s ⇒ Object
24
25
26
|
# File 'lib/axon-nats/msg.rb', line 24
def to_s
JSON.generate(@data)
end
|
#to_str ⇒ Object
27
28
29
|
# File 'lib/axon-nats/msg.rb', line 27
def to_str
to_s
end
|