Class: Karma::Messages::ProcessCommandMessage
- Inherits:
-
BaseKarmap
- Object
- Base
- BaseKarmap
- Karma::Messages::ProcessCommandMessage
- Defined in:
- lib/karma_messages/process_command_message.rb
Constant Summary collapse
- COMMANDS =
{start: 'start', stop: 'stop', restart: 'restart'}.freeze
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ ProcessCommandMessage
constructor
A new instance of ProcessCommandMessage.
- #parse(params) ⇒ Object
- #to_message ⇒ Object
Methods inherited from Base
#clear_errors, #message_type, #valid?
Constructor Details
#initialize(params) ⇒ ProcessCommandMessage
Returns a new instance of ProcessCommandMessage.
17 18 19 |
# File 'lib/karma_messages/process_command_message.rb', line 17 def initialize(params) super(params) end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/karma_messages/process_command_message.rb', line 5 def command @command end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
5 6 7 |
# File 'lib/karma_messages/process_command_message.rb', line 5 def pid @pid end |
Class Method Details
.services ⇒ Object
13 14 15 |
# File 'lib/karma_messages/process_command_message.rb', line 13 def self.services @@services end |
.services=(val) ⇒ Object
9 10 11 |
# File 'lib/karma_messages/process_command_message.rb', line 9 def self.services=(val) @@services = val end |
Instance Method Details
#parse(params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/karma_messages/process_command_message.rb', line 21 def parse(params) super(params) @@services ||= {} @errors << {service: 'Not a valid service'} if !@@services.empty? && !@@services.include?(params[:service]) @errors << {command: 'Required'} if params[:command].nil? @errors << {command: 'Not a valid command'} if !params[:command].nil? && !COMMANDS.values.include?(params[:command]) @errors << {pid: 'Required'} if params[:command] == 'stop' && params[:pid].nil? @command = params[:command] @pid = params[:pid] end |
#to_message ⇒ Object
33 34 35 36 37 38 |
# File 'lib/karma_messages/process_command_message.rb', line 33 def ret = super ret.merge!({ type: , command: @command}) ret.merge!({ pid: @pid}) if @command != COMMANDS[:start] ret end |