Sha256: ee583d936b7064c259fcee7dc2ee2aa55d08287d7689bf13d09669d95a749d0c

Contents?: true

Size: 900 Bytes

Versions: 2

Compression:

Stored size: 900 Bytes

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))
        read_responses(args[:regexp]) unless @in_command_list
      end
      send(:define_method, name, &block)
    end

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

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rmpd-1.0.1 lib/rmpd/commands/generators.rb
rmpd-1.0.0 lib/rmpd/commands/generators.rb