Class: Qrack::Protocol::Class::Method
- Inherits:
-
Object
- Object
- Qrack::Protocol::Class::Method
- Defined in:
- lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb,
lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.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 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb', line 5 def initialize *args opts = args.pop if args.last.is_a? Hash opts ||= {} if args.size == 1 and args.first.is_a? Transport::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
75 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb', line 75 def arguments() @arguments ||= [] end |
.id ⇒ Object
78 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb', line 78 def id() self::ID end |
.name ⇒ Object
79 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb', line 79 def name() self::NAME end |
.parent ⇒ Object
77 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb', line 77 def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end |
Instance Method Details
#==(b) ⇒ Object
82 83 84 85 86 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb', line 82 def == b self.class.arguments.inject(true) do |eql, (type, name)| eql and __send__("#{name}") == b.__send__("#{name}") end end |
#arguments ⇒ Object
22 23 24 25 26 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb', line 22 def arguments self.class.arguments.inject({}) do |hash, (type, name)| hash.update name => instance_variable_get("@#{name}") end end |
#to_binary ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb', line 28 def to_binary buf = Transport::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
58 59 60 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb', line 58 def to_frame channel = 0 Transport::Method.new(self, channel) end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb', line 54 def to_s to_binary.to_s end |