Class: Smith::ACL::Default

Inherits:
Object
  • Object
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.



11
12
13
# File 'lib/smith/messaging/acl/default.rb', line 11

def initialize(message={})
  @message = message
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, args) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/smith/messaging/acl/default.rb', line 39

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

#inspectObject



31
32
33
# File 'lib/smith/messaging/acl/default.rb', line 31

def inspect
  "<#{self.class.to_s}> -> #{(self.respond_to?(:to_hash)) ? self.to_hash : self.to_s}"
end

#parse_from_string(message) ⇒ Object



19
20
21
# File 'lib/smith/messaging/acl/default.rb', line 19

def parse_from_string(message)
  Marshal.load(message)
end

#serialize_to_stringObject



15
16
17
# File 'lib/smith/messaging/acl/default.rb', line 15

def serialize_to_string
  Marshal.dump(@message)
end

#to_hashObject



27
28
29
# File 'lib/smith/messaging/acl/default.rb', line 27

def to_hash
  @message && @message.to_hash
end

#to_jsonObject



35
36
37
# File 'lib/smith/messaging/acl/default.rb', line 35

def to_json
  MultiJson.dump(@message)
end

#to_sObject



23
24
25
# File 'lib/smith/messaging/acl/default.rb', line 23

def to_s
  @message.to_s
end