Skip to content
Browse files

minor refactoring on message's uuid

  • Loading branch information...
1 parent 314f1b1 commit cb0fa2d2cd85db4d110262a6aceb15d67ef3d1b3 @Horo Horo committed with horo
Showing with 11 additions and 8 deletions.
  1. +10 −1 lib/message.rb
  2. +1 −7 lib/message/header.rb
View
11 lib/message.rb
@@ -25,7 +25,8 @@ def initialize(opts={})
@header = Cucub::Message::Header.parse(opts["header"])
@body = Cucub::Message::Body.load(opts["body"])
else
- opts_for_header = opts.select{|key| ["from", "to", "respond_to", "layer", "uuid"].include?(key)}
+ opts_for_header = opts.select{|key| ["from", "to", "respond_to", "layer"].include?(key)}
+ opts_for_header["uuid"] = gen_uuid
@header = Cucub::Message::Header.new(opts_for_header)
@body = Cucub::Message::Body.new(opts["action"], opts["additionals"])
end
@@ -57,6 +58,14 @@ def action
def additionals
@body.additionals
end
+
+ private
+ def gen_uuid
+ uuid = self.object_id
+ uuid = -uuid if uuid < 0
+ uuid.to_s(35)
+ end
+
def self.parse(msg)
hash = MessagePack.unpack(msg)
View
8 lib/message/header.rb
@@ -11,13 +11,7 @@ def initialize(opts={})
@from = opts["from"]
@to = opts["to"]
@respond_to = opts["respond_to"]
- @uuid = opts["uuid"] || Cucub::Message::Header.gen_uuid(hash)
- end
-
- def self.gen_uuid(seed)
- uuid = seed
- uuid = -uuid if uuid < 0
- uuid.to_s(35)
+ @uuid = opts["uuid"]
end
def self.attrs

0 comments on commit cb0fa2d

Please sign in to comment.
Something went wrong with that request. Please try again.