Last active
March 6, 2018 09:32
-
-
Save slavakisel/0db94fa42e28ed981f2cbaee0da9aac5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Actions | |
| class Message | |
| TYPES = %w( | |
| PUSH_MESSAGE | |
| REMOVE_MESSAGE | |
| ).freeze | |
| attr_reader :type, :options | |
| def initialize(type, options) | |
| @type = type | |
| @options = options | |
| end | |
| def payload | |
| return {} unless valid? | |
| { | |
| type: type | |
| }.merge(payload_data) | |
| end | |
| def valid? | |
| TYPES.include?(type) | |
| end | |
| private | |
| def payload_data | |
| send(type.downcase) | |
| end | |
| def push_message | |
| { message: options[:message].decorate.as_json } | |
| end | |
| def remove_message | |
| { message_id: options[:message].id } | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment