Sha256: bdd71a6704c6916fb90cee3c6e86850566706d10adf9b6896e759de4811d6c84

Contents?: true

Size: 1.87 KB

Versions: 40

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

class RedisClient
  module CommandBuilder
    extend self

    if Symbol.method_defined?(:name)
      def generate(args, kwargs = nil)
        command = args.flat_map do |element|
          case element
          when Hash
            element.flatten
          else
            element
          end
        end

        kwargs&.each do |key, value|
          if value
            if value == true
              command << key.name
            else
              command << key.name << value
            end
          end
        end

        command.map! do |element|
          case element
          when String
            element
          when Symbol
            element.name
          when Integer, Float
            element.to_s
          else
            raise TypeError, "Unsupported command argument type: #{element.class}"
          end
        end

        if command.empty?
          raise ArgumentError, "can't issue an empty redis command"
        end

        command
      end
    else
      def generate(args, kwargs = nil)
        command = args.flat_map do |element|
          case element
          when Hash
            element.flatten
          else
            element
          end
        end

        kwargs&.each do |key, value|
          if value
            if value == true
              command << key.to_s
            else
              command << key.to_s << value
            end
          end
        end

        command.map! do |element|
          case element
          when String
            element
          when Integer, Float, Symbol
            element.to_s
          else
            raise TypeError, "Unsupported command argument type: #{element.class}"
          end
        end

        if command.empty?
          raise ArgumentError, "can't issue an empty redis command"
        end

        command
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
redis-client-0.23.2 lib/redis_client/command_builder.rb
redis-client-0.23.1 lib/redis_client/command_builder.rb
redis-client-0.23.0 lib/redis_client/command_builder.rb
redis-client-0.22.1 lib/redis_client/command_builder.rb
redis-client-0.22.0 lib/redis_client/command_builder.rb
redis-client-0.21.1 lib/redis_client/command_builder.rb
redis-client-0.21.0 lib/redis_client/command_builder.rb
redis-client-0.20.0 lib/redis_client/command_builder.rb
redis-client-0.19.1 lib/redis_client/command_builder.rb
redis-client-0.19.0 lib/redis_client/command_builder.rb
redis-client-0.18.0 lib/redis_client/command_builder.rb
redis-client-0.17.1 lib/redis_client/command_builder.rb
redis-client-0.17.0 lib/redis_client/command_builder.rb
redis-client-0.16.0 lib/redis_client/command_builder.rb
redis-client-0.15.0 lib/redis_client/command_builder.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/redis-client-0.12.0/lib/redis_client/command_builder.rb
redis-client-0.14.1 lib/redis_client/command_builder.rb
redis-client-0.14.0 lib/redis_client/command_builder.rb
redis-client-0.13.0 lib/redis_client/command_builder.rb
redis-client-0.12.2 lib/redis_client/command_builder.rb