Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Forwardable within Message to avoid method boilerplate #681

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions lib/shoryuken/message.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
module Shoryuken
class Message
extend Forwardable

def_delegators(:data,
:message_id,
:receipt_handle,
:md5_of_body,
:body,
:attributes,
:md5_of_message_attributes,
:message_attributes)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor thing but skipping the parentheses in this case would match the macro-style methods better and also sorting the lines ascending would make it easier to read, e.g.:

def_delegators :attributes,
               :body,
               :data,
               :md5_of_body,
               :md5_of_message_attributes,
               :message_attributes,
               :message_id,
               :receipt_handle

attr_accessor :client, :queue_url, :queue_name, :data

def initialize(client, queue, data)
Expand Down Expand Up @@ -29,33 +40,5 @@ def visibility_timeout=(timeout)
visibility_timeout: timeout
)
end

def message_id
data.message_id
end

def receipt_handle
data.receipt_handle
end

def md5_of_body
data.md5_of_body
end

def body
data.body
end

def attributes
data.attributes
end

def md5_of_message_attributes
data.md5_of_message_attributes
end

def message_attributes
data.message_attributes
end
end
end