class Qpid::Proton::Codec::Mapping
Maps between Proton
types and their Ruby native language counterparts.
@private
Attributes
code[R]
get_method[R]
put_method[R]
Public Class Methods
[](x)
click to toggle source
Convert x to a Mapping
# File lib/codec/mapping.rb, line 87 def self.[](x) case x when Mapping then x when Integer then @@by_code[x] when Types::Type then @@by_code[x.code] end end
for_class(klass)
click to toggle source
# File lib/codec/mapping.rb, line 75 def self.for_class(klass) c = klass c = c.superclass while c && (x = @@by_class[c]).nil? raise TypeError, "#{klass} cannot be converted to AMQP" unless x x end
for_code(code)
click to toggle source
# File lib/codec/mapping.rb, line 82 def self.for_code(code) @@by_code[code] end
new(code, name, klasses = nil, getter = nil)
click to toggle source
Creates a new mapping.
Arguments¶ ↑
-
code - the AMQP code for this type
-
name - the AMQP name for this type
-
klasses - native Ruby classes that are mapped to this AMQP type
-
getter - overrides the get method for the type
# File lib/codec/mapping.rb, line 42 def initialize(code, name, klasses = nil, getter = nil) @code = code @name = name @@by_code[code] = self unless klasses.nil? klasses.each do |klass| raise "entry exists for #{klass}" if @@by_class.keys.include? klass @@by_class[klass] = self unless klass.nil? end end @put_method = (name + "=").intern if getter.nil? @get_method = name.intern else @get_method = getter.intern end end
Public Instance Methods
get(data)
click to toggle source
# File lib/codec/mapping.rb, line 71 def get(data) data.__send__(@get_method) end
put(data, value)
click to toggle source
# File lib/codec/mapping.rb, line 67 def put(data, value) data.__send__(@put_method, value) end
to_s()
click to toggle source
# File lib/codec/mapping.rb, line 65 def to_s; @name; end