Sha256: 18b9a98c765cf19df44164b91f699f0dbe2dcc903c7e5b1741b9ac3014b9fa32

Contents?: true

Size: 1.69 KB

Versions: 190

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module Seahorse
  module Client
    module Plugins

      # Defines a helper method for each API operation that builds and
      # sends the named request.
      #
      # # Helper Methods
      #
      # This plugin adds a helper method that lists the available API
      # operations.
      #
      #     client.operation_names
      #     #=> [:api_operation_name1, :api_operation_name2, ...]
      #
      # Additionally, it adds a helper method for each operation.  This helper
      # handles building and sending the appropriate {Request}.
      #
      #     # without OperationMethods plugin
      #     req = client.build_request(:api_operation_name, request_params)
      #     resp = req.send_request
      #
      #     # using the helper method defined by OperationMethods
      #     resp = client.api_operation_name(request_params)
      #
      class OperationMethods < Plugin

        def after_initialize(client)
          unless client.respond_to?(:operation_names)
            client.class.mutex.synchronize do
              unless client.respond_to?(:operation_names)
                add_operation_helpers(client, client.config.api.operation_names)
              end
            end
          end
        end

        def add_operation_helpers(client, operations)
          operations.each do |name|
            client.class.send(:define_method, name) do |*args, &block|
              params = args[0] || {}
              send_options = args[1] || {}
              build_request(name, params).send_request(send_options, &block)
            end
          end
          client.class.send(:define_method, :operation_names) { operations }
        end

      end
    end
  end
end

Version data entries

190 entries across 190 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.213.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.212.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.211.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.210.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.209.1 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.209.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.208.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.207.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.206.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.205.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.204.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.203.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.202.2 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.202.1 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.202.0 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.201.5 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.201.4 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.201.3 lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-3.201.2 lib/seahorse/client/plugins/operation_methods.rb