Sha256: 67f487ae3173b5eb379ccb2d794a83d9d5a25dfe8dc8bf37a5077396fcea4955

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

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
              add_operation_helpers(client, client.config.api.operations.keys)
            end
          end
        end

        def add_operation_helpers(client, operations)
          client.class.send(:define_method, :operation_names) { 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
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
aws-sdk-core-2.0.0.rc8 vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-2.0.0.rc7 vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-2.0.0.rc6 vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-2.0.0.rc5 vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-2.0.0.rc4 vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb
aws-sdk-core-2.0.0.rc3 vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb