Parent

AMQP::Protocol::Class::Method

Public Class Methods

new(*args) click to toggle source
# File lib/amqp/protocol.rb, line 8
def initialize *args
  opts = args.pop if args.last.is_a? Hash
  opts ||= {}
  
  @debug = 1 # XXX hack, p(obj) == '' if no instance vars are set
  
  if args.size == 1 and args.first.is_a? Buffer
    buf = args.shift
  else
    buf = nil
  end

  self.class.arguments.each do |type, name|
    val = buf ? buf.read(type) :
                args.shift || opts[name] || opts[name.to_s]
    instance_variable_set("@#{name}", val)
  end
end

Public Instance Methods

arguments() click to toggle source
# File lib/amqp/protocol.rb, line 27
def arguments
  self.class.arguments.inject({}) do |hash, (type, name)|
    hash.update name => instance_variable_get("@#{name}")
  end
end
to_binary() click to toggle source
# File lib/amqp/protocol.rb, line 33
def to_binary
  buf = Buffer.new
  buf.write :short, self.class.section.id
  buf.write :short, self.class.id

  bits = []

  self.class.arguments.each do |type, name|
    val = instance_variable_get("@#{name}")
    if type == :bit
      bits << (val || false)
    else
      unless bits.empty?
        buf.write :bit, bits
        bits = []
      end
      buf.write type, val
    end
  end

  buf.write :bit, bits unless bits.empty?
  buf.rewind

  buf
end
to_frame(channel = 0) click to toggle source
# File lib/amqp/protocol.rb, line 63
def to_frame channel = 0
  Frame::Method.new(self, channel)
end
to_s() click to toggle source
# File lib/amqp/protocol.rb, line 59
def to_s
  to_binary.to_s
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.