Class: Qpid::Proton::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/qpid_proton/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



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
68
# File 'lib/qpid_proton/mapping.rb', line 40

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.



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

def code
  @code
end

#get_methodObject (readonly)

Returns the value of attribute get_method.



30
31
32
# File 'lib/qpid_proton/mapping.rb', line 30

def get_method
  @get_method
end

#put_methodObject (readonly)

Returns the value of attribute put_method.



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

def put_method
  @put_method
end

Class Method Details

.for_class(klass) ⇒ Object

:nodoc:



80
81
82
# File 'lib/qpid_proton/mapping.rb', line 80

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

.for_code(code) ⇒ Object



84
85
86
# File 'lib/qpid_proton/mapping.rb', line 84

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

Instance Method Details

#get(data) ⇒ Object



76
77
78
# File 'lib/qpid_proton/mapping.rb', line 76

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

#put(data, value) ⇒ Object



72
73
74
# File 'lib/qpid_proton/mapping.rb', line 72

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

#to_sObject



70
# File 'lib/qpid_proton/mapping.rb', line 70

def to_s; @name; end