Class: AMQP::Protocol::Class::Method
- Inherits:
-
Object
- Object
- AMQP::Protocol::Class::Method
- Defined in:
- lib/amqp/protocol.rb,
lib/amqp/spec.rb
Overview
:stopdoc:
Class Method Summary collapse
Instance Method Summary collapse
- #==(b) ⇒ Object
- #arguments ⇒ Object
-
#initialize(*args) ⇒ Method
constructor
A new instance of Method.
- #to_binary ⇒ Object
- #to_frame(channel = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Method
Returns a new instance of Method.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
Class Method Details
.arguments ⇒ Object
97 |
# File 'lib/amqp/spec.rb', line 97 def arguments() @arguments ||= [] end |
.id ⇒ Object
100 |
# File 'lib/amqp/spec.rb', line 100 def id() self::ID end |
.name ⇒ Object
101 |
# File 'lib/amqp/spec.rb', line 101 def name() self::NAME end |
.section ⇒ Object
99 |
# File 'lib/amqp/spec.rb', line 99 def section() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end |
Instance Method Details
#==(b) ⇒ Object
104 105 106 107 108 |
# File 'lib/amqp/spec.rb', line 104 def == b self.class.arguments.inject(true) do |eql, (type, name)| eql and __send__("#{name}") == b.__send__("#{name}") end end |
#arguments ⇒ Object
27 28 29 30 31 |
# 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 ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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) ⇒ Object
63 64 65 |
# File 'lib/amqp/protocol.rb', line 63 def to_frame channel = 0 Frame::Method.new(self, channel) end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/amqp/protocol.rb', line 59 def to_s to_binary.to_s end |