Class: Qpid::Proton::Codec::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/codec/mapping.rb

Overview

Maps between Proton types and their Ruby native language counterparts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, name, klasses = nil, getter = nil) ⇒ Mapping

Creates a new mapping.

Arguments

  • code - the AMQP code for this type

  • name - the AMQP name for this type

  • klasses - the Ruby classes for this type

  • getter - overrides the get method for the type



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/codec/mapping.rb', line 39

def initialize(code, name, klasses = nil, getter = nil)

  @debug = (name == "bool")

  @code = code
  @name = name

  @@by_preferred ||= {}
  @@by_code ||= {}
  @@by_code["#{code}"] = self
  @@by_name ||= {}
  @@by_name[name] = self
  @@by_class ||= {}

  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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



27
28
29
# File 'lib/codec/mapping.rb', line 27

def code
  @code
end

#get_methodObject (readonly)

Returns the value of attribute get_method.



29
30
31
# File 'lib/codec/mapping.rb', line 29

def get_method
  @get_method
end

#put_methodObject (readonly)

Returns the value of attribute put_method.



28
29
30
# File 'lib/codec/mapping.rb', line 28

def put_method
  @put_method
end

Class Method Details

.for_class(klass) ⇒ Object

:nodoc:



79
80
81
# File 'lib/codec/mapping.rb', line 79

def self.for_class(klass) # :nodoc:
  @@by_class[klass]
end

.for_code(code) ⇒ Object



83
84
85
# File 'lib/codec/mapping.rb', line 83

def self.for_code(code)
  @@by_code["#{code}"]
end

Instance Method Details

#get(data) ⇒ Object



75
76
77
# File 'lib/codec/mapping.rb', line 75

def get(data)
  data.__send__(@get_method)
end

#put(data, value) ⇒ Object



71
72
73
# File 'lib/codec/mapping.rb', line 71

def put(data, value)
  data.__send__(@put_method, value)
end

#to_sObject



69
# File 'lib/codec/mapping.rb', line 69

def to_s; @name; end