Class: SOAP::Mapping::EncodedRegistry::Map
- Defined in:
- lib/soap/mapping/encodedregistry.rb
Instance Method Summary collapse
-
#add(obj_class, soap_class, factory, info) ⇒ Object
Give priority to latter entry.
- #clear ⇒ Object
- #find_mapped_obj_class(target_soap_class) ⇒ Object
- #find_mapped_soap_class(target_obj_class) ⇒ Object
-
#init(init_map = []) ⇒ Object
Give priority to former entry.
-
#initialize(registry) ⇒ Map
constructor
A new instance of Map.
- #obj2soap(obj) ⇒ Object
-
#soap2obj(node, klass = nil) ⇒ Object
estrae i dati dall’XML di origine.
Constructor Details
#initialize(registry) ⇒ Map
Returns a new instance of Map.
53 54 55 56 57 |
# File 'lib/soap/mapping/encodedregistry.rb', line 53 def initialize(registry) @obj2soap = {} @soap2obj = {} @registry = registry end |
Instance Method Details
#add(obj_class, soap_class, factory, info) ⇒ Object
Give priority to latter entry.
101 102 103 104 105 |
# File 'lib/soap/mapping/encodedregistry.rb', line 101 def add(obj_class, soap_class, factory, info) info ||= {} (@obj2soap[obj_class] ||= []).unshift([soap_class, factory, info]) (@soap2obj[soap_class] ||= []).unshift([obj_class, factory, info]) end |
#clear ⇒ Object
107 108 109 110 |
# File 'lib/soap/mapping/encodedregistry.rb', line 107 def clear @obj2soap.clear @soap2obj.clear end |
#find_mapped_obj_class(target_soap_class) ⇒ Object
117 118 119 120 |
# File 'lib/soap/mapping/encodedregistry.rb', line 117 def find_mapped_obj_class(target_soap_class) map = @soap2obj[target_soap_class] map.empty? ? nil : map[0][0] end |
#find_mapped_soap_class(target_obj_class) ⇒ Object
112 113 114 115 |
# File 'lib/soap/mapping/encodedregistry.rb', line 112 def find_mapped_soap_class(target_obj_class) map = @obj2soap[target_obj_class] map.empty? ? nil : map[0][1] end |
#init(init_map = []) ⇒ Object
Give priority to former entry.
93 94 95 96 97 98 |
# File 'lib/soap/mapping/encodedregistry.rb', line 93 def init(init_map = []) clear init_map.reverse_each do |obj_class, soap_class, factory, info| add(obj_class, soap_class, factory, info) end end |
#obj2soap(obj) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/soap/mapping/encodedregistry.rb', line 59 def obj2soap(obj) klass = obj.class if map = @obj2soap[klass] map.each do |soap_class, factory, info| ret = factory.obj2soap(soap_class, obj, info, @registry) return ret if ret end end klass.ancestors.each do |baseclass| next if baseclass == klass if map = @obj2soap[baseclass] map.each do |soap_class, factory, info| if info[:derived_class] ret = factory.obj2soap(soap_class, obj, info, @registry) return ret if ret end end end end nil end |
#soap2obj(node, klass = nil) ⇒ Object
estrae i dati dall’XML di origine
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/soap/mapping/encodedregistry.rb', line 81 def soap2obj(node, klass = nil) if map = @soap2obj[node.class] map.each do |obj_class, factory, info| next if klass and obj_class != klass conv, obj = factory.soap2obj(obj_class, node, info, @registry) return true, obj if conv end end return false, nil end |