Sha256: 322dbea73436d8fabe9f1f4f7073a6642a2e3b4521abca77d96d7319b962c652

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

module Rmpd
  module Commands

    private

    def self.simple_command(name, args={})
      block = lambda do |*a|
        if args.include?(:min_version)
          server_version_at_least(*args[:min_version])
        end
        send_command(name.to_s.gsub(/^_*/, ""), *quote(a))
        read_response unless @in_command_list
      end
      send(:define_method, name, &block)
    end

    def self.complex_command(name, args={})
      args = {:regexp => /(^file: )/i}.merge(args)
      block = lambda do |*a|
        if args.include?(:min_version)
          server_version_at_least(*args[:min_version])
        end
        send_command(name.to_s.gsub(/^_*/, ""), *quote(a))
        if @in_command_list
          append_command_list_regexp(args[:regexp])
        else
          read_responses(args[:regexp])
        end
      end
      send(:define_method, name, &block)
    end

    def append_command_list_regexp(regexp)
      if @in_command_list_response_regexp
        @in_command_list_response_regexp = \
          Regexp.union(@in_command_list_response_regexp, regexp)
      else
        @in_command_list_response_regexp = regexp
      end
    end

    def quote(args)
      args.collect {|arg| "\"#{arg.to_s.gsub(/"/, "\\\"")}\""}
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rmpd-1.0.5 lib/rmpd/commands/generators.rb
rmpd-1.0.4 lib/rmpd/commands/generators.rb
rmpd-1.0.3 lib/rmpd/commands/generators.rb
rmpd-1.0.2 lib/rmpd/commands/generators.rb