Class: AwsDevUtils::ClientWrapper

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/aws-dev-utils/client_wrapper.rb

Instance Method Summary collapse

Methods included from Utils

nested_hash, nested_struct

Constructor Details

#initialize(client, options = {}) ⇒ ClientWrapper

Initialize a new ClientWrapper, internal use only

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • next_token (String)

    max number of requests

  • retry (String)

    max number of retries

  • cache (String)

    the key-value timeout



11
12
13
14
# File 'lib/aws-dev-utils/client_wrapper.rb', line 11

def initialize client, options={}
  @client = client
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/aws-dev-utils/client_wrapper.rb', line 31

def method_missing m, *args, &block
  client_name = @client.class.name
  @client = RetryWrapper.new(@client, @options[:retry]) if retry?
  @client = NextTokenWrapper.new(@client, @options[:next_token]) if next_token?
  @client = CacheWrapper.new(@client, @options[:cache], client_name: client_name) if cache?

  nested_struct(@client.send(m, *args, &block))
end

Instance Method Details

#with_cache(exp = 60) ⇒ Object

Returns ClientWrapper with cache option.

Returns:

  • ClientWrapper with cache option



27
28
29
# File 'lib/aws-dev-utils/client_wrapper.rb', line 27

def with_cache exp=60
  self.class.new(@client, @options.merge(cache: exp))
end

#with_next_token(max = 100) ⇒ Object

Returns ClientWrapper with next_token option.

Returns:

  • ClientWrapper with next_token option



17
18
19
# File 'lib/aws-dev-utils/client_wrapper.rb', line 17

def with_next_token max=100
  self.class.new(@client, @options.merge(next_token: max))
end

#with_retry(max = 5) ⇒ Object

Returns ClientWrapper with retry option.

Returns:

  • ClientWrapper with retry option



22
23
24
# File 'lib/aws-dev-utils/client_wrapper.rb', line 22

def with_retry max=5
  self.class.new(@client, @options.merge(retry: max))
end