@@ -123,20 +123,25 @@ def to_s
123
123
124
124
private
125
125
126
- # Internal: Delegate the method to the API if it exists.
127
- #
128
- # This allows `api.posts` instead of `api.links.posts.embedded`
126
+ # Internal: Delegate the method further down the API if the resource cannot serve it.
129
127
def method_missing ( method , *args , &block )
130
- if @key && _resource . respond_to? ( @key ) && ( delegate = _resource . send ( @key ) ) && delegate . respond_to? ( method . to_s )
131
- # named.named becomes named
132
- delegate . send ( method , *args , &block )
133
- elsif _resource . respond_to? ( method . to_s )
134
- _resource . send ( method , *args , &block )
128
+ if _resource . respond_to? ( method . to_s )
129
+ _resource . send ( method , *args , &block ) || delegate_method ( method , *args , &block )
135
130
else
136
131
super
137
132
end
138
133
end
139
134
135
+ # Internal: Delegate the method to the API if the resource cannot serve it.
136
+ #
137
+ # This allows `api.posts` instead of `api._links.posts.embedded.posts`
138
+ def delegate_method ( method , *args , &block )
139
+ return unless @key && _resource . respond_to? ( @key )
140
+ @delegate ||= _resource . send ( @key )
141
+ return unless @delegate && @delegate . respond_to? ( method . to_s )
142
+ @delegate . send ( method , *args , &block )
143
+ end
144
+
140
145
# Internal: Accessory method to allow the link respond to the
141
146
# methods that will hit method_missing.
142
147
def respond_to_missing? ( method , _include_private = false )
0 commit comments