class Evostream::Commands::Command

Class parent for all command

Public Class Methods

descendants() click to toggle source
# File lib/evostream/event/commands.rb, line 26
def self.descendants
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end
new(commands = {}) click to toggle source
# File lib/evostream/event/commands.rb, line 14
def initialize(commands = {})
  @command = []
  commands.each do |command_name, command_param|
    @command.push send(command_name, command_param)
  end
  test_missing_parameter
end

Public Instance Methods

cmd() click to toggle source
# File lib/evostream/event/commands.rb, line 22
def cmd
  Evostream.logger "Command before encode : #{@command}"
end

Private Instance Methods

encode64() click to toggle source

Encode commands in base 64 with space between each command

# File lib/evostream/event/commands.rb, line 33
def encode64
  Base64.strict_encode64(@command.join(' '))
end
missing_parameter() click to toggle source
# File lib/evostream/event/commands.rb, line 43
def missing_parameter
  self.class::MANDATORY.none? do |method|
    @command.any? do |part_payload|
      part_payload.match?(/#{method}/)
    end
  end
end
test_missing_parameter() click to toggle source
# File lib/evostream/event/commands.rb, line 37
def test_missing_parameter
  missing = self.class::MANDATORY.empty? ? false : missing_parameter
  raise Errors::MissingMandatory.new(self.class::MANDATORY, self.class) \
    if missing
end