Sha256: abfa59d7738cb5b41e263bc89bebf6d4f518d477a1e3c876ba39dd62fae799fc

Contents?: true

Size: 1.6 KB

Versions: 13

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'base64'

# :reek:UncommunicativeMethodName
# :reek:NestedIterators
# :reek:DuplicateMethodCall

module Evostream
  # Manage command
  module Commands
    # Class parent for all command
    class Command
      def initialize(commands = {})
        @command = []
        commands.each do |command_name, command_param|
          @command.push send(command_name, command_param)
        end
        test_missing_parameter
      end

      def cmd
        Evostream.logger "Command before encode : #{@command}"
      end

      def self.descendants
        ObjectSpace.each_object(Class).select { |klass| klass < self }
      end

      private

      # Encode commands in base 64 with space between each command
      def encode_64
        Base64.strict_encode64(@command.join(' '))
      end

      def test_missing_parameter
        missing = self.class::MANDATORY.empty? ? false : missing_parameter
        raise Errors::MissingMandatory.new(self.class::MANDATORY, self.class) \
          if missing
      end

      def missing_parameter
        self.class::MANDATORY.none? do |method|
          @command.any? do |part_payload|
            part_payload.match?(/#{method}/)
          end
        end
      end
    end
  end
end

require 'evostream/event/commands/error'
require 'evostream/event/commands/create'
require 'evostream/event/commands/destroy'
require 'evostream/event/commands/get_stream_info'
require 'evostream/event/commands/list_config'
require 'evostream/event/commands/list_streams'
require 'evostream/event/commands/push_stream'
require 'evostream/event/commands/set_log_level'

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
evostream-event-1.0.3 lib/evostream/event/commands.rb
evostream-event-1.0.3.pre.95 lib/evostream/event/commands.rb
evostream-event-1.0.3.pre.93 lib/evostream/event/commands.rb
evostream-event-1.0.3.pre.91 lib/evostream/event/commands.rb
evostream-event-1.0.3.pre.83 lib/evostream/event/commands.rb
evostream-event-1.0.2 lib/evostream/event/commands.rb
evostream-event-1.0.2.pre.75 lib/evostream/event/commands.rb
evostream-event-1.0.2.pre.74 lib/evostream/event/commands.rb
evostream-event-1.0.1 lib/evostream/event/commands.rb
evostream-event-1.0.1.pre.72 lib/evostream/event/commands.rb
evostream-event-1.0.0 lib/evostream/event/commands.rb
evostream-event-1.0.0.pre.69 lib/evostream/event/commands.rb
evostream-event-1.0.0.pre.65 lib/evostream/event/commands.rb