Class: Smith::ACL::Default
- Inherits:
-
Object
- Object
- Smith::ACL::Default
show all
- Defined in:
- lib/smith/messaging/acl/default.rb
Overview
Default message. This takes any object that can be marshalled. If no content is passed in on the constructor then an the message is assigned an empty Hash. method_missing is declared and will update the hash.
Instance Method Summary
collapse
Constructor Details
#initialize(message = {}) ⇒ Default
Returns a new instance of Default.
14
15
16
|
# File 'lib/smith/messaging/acl/default.rb', line 14
def initialize(message={})
@message = message
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, args) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/smith/messaging/acl/default.rb', line 42
def method_missing(method, args)
match = /(.*?)=$/.match(method.to_s)
if match && match[1]
index = match[1].to_sym
@message[index] = args
else
raise NoMethodError, "undefined method `#{method}' for #{self}", caller
end
end
|
Instance Method Details
#inspect ⇒ Object
34
35
36
|
# File 'lib/smith/messaging/acl/default.rb', line 34
def inspect
"<#{self.class.to_s}> -> #{(self.respond_to?(:to_hash)) ? self.to_hash : self.to_s}"
end
|
#parse_from_string(message) ⇒ Object
22
23
24
|
# File 'lib/smith/messaging/acl/default.rb', line 22
def parse_from_string(message)
Marshal.load(message)
end
|
#serialize_to_string ⇒ Object
18
19
20
|
# File 'lib/smith/messaging/acl/default.rb', line 18
def serialize_to_string
Marshal.dump(@message)
end
|
#to_hash ⇒ Object
30
31
32
|
# File 'lib/smith/messaging/acl/default.rb', line 30
def to_hash
@message && @message.to_hash
end
|
#to_json ⇒ Object
38
39
40
|
# File 'lib/smith/messaging/acl/default.rb', line 38
def to_json
MultiJson.dump(@message)
end
|
#to_s ⇒ Object
26
27
28
|
# File 'lib/smith/messaging/acl/default.rb', line 26
def to_s
@message.to_s
end
|