smacks-savon 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/savon/response.rb +11 -8
- metadata +1 -1
data/lib/savon/response.rb
CHANGED
@@ -68,7 +68,7 @@ module Savon
|
|
68
68
|
|
69
69
|
# Sets the default root node.
|
70
70
|
def self.default_root_node=(root_node)
|
71
|
-
@@default_root_node = root_node if root_node.kind_of?
|
71
|
+
@@default_root_node = root_node if root_node.kind_of?(String)
|
72
72
|
end
|
73
73
|
|
74
74
|
# The core (inherited) methods to shadow.
|
@@ -81,7 +81,7 @@ module Savon
|
|
81
81
|
|
82
82
|
# Sets the core +methods+ to shadow.
|
83
83
|
def self.core_methods_to_shadow=(methods)
|
84
|
-
@@core_methods_to_shadow = methods if methods.kind_of?
|
84
|
+
@@core_methods_to_shadow = methods if methods.kind_of?(Array)
|
85
85
|
end
|
86
86
|
|
87
87
|
# Initializer expects the +source+ to initialize from. Sets up the instance
|
@@ -90,14 +90,15 @@ module Savon
|
|
90
90
|
# in case the given +source+ is a Net::HTTPResponse.
|
91
91
|
def initialize(source, root_node = nil)
|
92
92
|
if source.kind_of? Hash
|
93
|
-
initialize_from_hash
|
93
|
+
initialize_from_hash(source)
|
94
94
|
elsif source.respond_to? :body
|
95
|
-
initialize_from_response
|
95
|
+
initialize_from_response(source, root_node)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
# Returns the value from a given +key+ from the response Hash.
|
100
100
|
def [](key)
|
101
|
+
return @hash unless @hash.kind_of?(Hash)
|
101
102
|
value_from_hash(key)
|
102
103
|
end
|
103
104
|
|
@@ -119,8 +120,10 @@ module Savon
|
|
119
120
|
# Returns a new Savon::Response instance containing the value or returns
|
120
121
|
# the actual value in case it is not a Hash.
|
121
122
|
def method_missing(method, *args)
|
123
|
+
return @hash unless @hash.kind_of?(Hash)
|
124
|
+
|
122
125
|
value = value_from_hash(method)
|
123
|
-
return value unless value.kind_of?
|
126
|
+
return value unless value.kind_of?(Hash)
|
124
127
|
Savon::Response.new(value)
|
125
128
|
end
|
126
129
|
|
@@ -138,14 +141,14 @@ module Savon
|
|
138
141
|
if success?
|
139
142
|
root_node ||= @@default_root_node
|
140
143
|
hash = response_to_hash(root_node)
|
141
|
-
initialize_from_hash
|
144
|
+
initialize_from_hash(hash)
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
145
148
|
# Initializes the instance from a given +hash+.
|
146
149
|
def initialize_from_hash(hash)
|
147
150
|
@hash = hash
|
148
|
-
shadow_core_methods
|
151
|
+
shadow_core_methods if @hash.kind_of?(Hash)
|
149
152
|
end
|
150
153
|
|
151
154
|
# Dynamically defines methods from the Array of +@@core_methods_to_shadow+
|
@@ -153,7 +156,7 @@ module Savon
|
|
153
156
|
# case a matching public method and a key from the Hash could be found.
|
154
157
|
def shadow_core_methods
|
155
158
|
@@core_methods_to_shadow.each do |method|
|
156
|
-
if self.public_methods.include?(method.to_s) &&
|
159
|
+
if self.public_methods.include?(method.to_s) && value_from_hash(method)
|
157
160
|
self.class.send(:define_method, method) { value_from_hash(method) }
|
158
161
|
end
|
159
162
|
end
|