Class: Carrot::AMQP::Protocol::Class::Method
- Inherits:
-
Object
- Object
- Carrot::AMQP::Protocol::Class::Method
- Defined in:
- lib/carrot/amqp/protocol.rb,
lib/carrot/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.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/carrot/amqp/protocol.rb', line 5 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
85 |
# File 'lib/carrot/amqp/spec.rb', line 85 def arguments() @arguments ||= [] end |
.id ⇒ Object
88 |
# File 'lib/carrot/amqp/spec.rb', line 88 def id() self::ID end |
.name ⇒ Object
89 |
# File 'lib/carrot/amqp/spec.rb', line 89 def name() self::NAME end |
.parent ⇒ Object
87 |
# File 'lib/carrot/amqp/spec.rb', line 87 def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end |
Instance Method Details
#==(b) ⇒ Object
92 93 94 95 96 |
# File 'lib/carrot/amqp/spec.rb', line 92 def == b self.class.arguments.inject(true) do |eql, (type, name)| eql and __send__("#{name}") == b.__send__("#{name}") end end |
#arguments ⇒ Object
24 25 26 27 28 |
# File 'lib/carrot/amqp/protocol.rb', line 24 def arguments self.class.arguments.inject({}) do |hash, (type, name)| hash.update name => instance_variable_get("@#{name}") end end |
#to_binary ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/carrot/amqp/protocol.rb', line 30 def to_binary buf = Buffer.new buf.write :short, self.class.parent.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
60 61 62 |
# File 'lib/carrot/amqp/protocol.rb', line 60 def to_frame channel = 0 Frame::Method.new(self, channel) end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/carrot/amqp/protocol.rb', line 56 def to_s to_binary.to_s end |