Module: PulpPolymorphicRemoteResponsePatch

Defined in:
lib/monkeys/pulp_polymorphic_remote_response.rb

Overview

Helper module to patch Remote API classes

Class Method Summary collapse

Class Method Details

.patch_remote_method(klass, method_name) ⇒ Object

Patch a Remote API class’s update methods to return AsyncOperationResponse



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/monkeys/pulp_polymorphic_remote_response.rb', line 48

def self.patch_remote_method(klass, method_name)
  # We need to patch the _with_http_info method since that's where return_type is set
  with_http_info_method = :"#{method_name}_with_http_info"

  klass.class_eval do
    # Save reference to original _with_http_info method
    original_method = :"#{with_http_info_method}_original"
    alias_method original_method, with_http_info_method

    # Override the _with_http_info method to force AsyncOperationResponse return type
    define_method(with_http_info_method) do |href, data, opts = {}|
      # The generated bindings code uses: return_type = opts[:debug_return_type] || 'RpmRpmRemoteResponse' for example
      # By setting debug_return_type to AsyncOperationResponse, we override the default
      modified_opts = (opts || {}).merge(debug_return_type: 'AsyncOperationResponse')

      # Call original method with modified opts
      send(original_method, href, data, modified_opts)
    end
  end
end