aws-dev-utils 1.4.4 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34a8659230582635341c256080cf9799b0a61a1e0b310234f8d86a695460cbba
4
- data.tar.gz: 540c636ebcb5c10668575ed17ce64832e9e88932582a89250f85f87db6965900
3
+ metadata.gz: b8b0b00bc92f14545ee09e8bbcbed7faf6157a65baefd27b7bfc2e0efe4c036e
4
+ data.tar.gz: 0f4491633cd884b69007d55f44630f866c01d5f186fdb49f88dab43254a4023b
5
5
  SHA512:
6
- metadata.gz: 8dcd8e2f81e666beed0e3e96cdaea536024f2acd9f6b839bf9086e42b175af4d9e4d2c997484eb4c2c20d5f763d43bac871159fd046c0b071836924b767e7ad1
7
- data.tar.gz: 9ec27b077aa93bba943e5d188fb8fab8ecf80dc2b9e7ff8bff226da57496c379d20b8ee4c6961f869b0f690a6017ca6327d8bbc35aca27a83f8ad41f392b1224
6
+ metadata.gz: e127faa71bf9a1ebbc9cbc61ee21ddb85f50ad939fd9265875bfe78547a3140fe8d585ca9a615251782104c1edf863419eebbafa3d4197da309a6f9b8a3cb35c
7
+ data.tar.gz: b68e630e50243ce54e219ff4ce460d2f1ea15573a53ae85095bb341e33860f238add531e004caadc87376a797756f84e37386006dbe98faa36b57e916f908135
@@ -6,11 +6,16 @@ module AwsDevUtils
6
6
  @hash = {}
7
7
  end
8
8
 
9
+ # Get the value of key, if not found, returns nil.
9
10
  def get key
10
11
  clean_cache!
11
12
  @hash[key][1]
12
13
  end
13
14
 
15
+ # Set key to hold the value and set key to timeout after the a given expiration time(in seconds).
16
+ # @param key [Object]
17
+ # @param value [Object]
18
+ # @param exp [Integer] - the key-value timeout
14
19
  def set key, value, exp
15
20
  clean_cache!
16
21
  @hash[key] = [Time.now + exp, value]
@@ -4,13 +4,13 @@ module AwsDevUtils
4
4
  module Backend
5
5
  class Redis
6
6
  # :nocov:
7
- # Initialize a new redis client
8
- # @param [String] url - specify redis url connection
7
+ # Initialize a new redis client.
8
+ # @params url [String] - specify redis url connection
9
9
  def initialize url='redis://localhost:6379'
10
10
  @redis = ::Redis.new(url: url)
11
11
  end
12
12
 
13
- # Get the value of key. If not found returns nil
13
+ # Get the value of key, if not found, returns nil.
14
14
  def get key
15
15
  @redis.get key
16
16
  end
@@ -5,7 +5,7 @@ module AwsDevUtils
5
5
  class Cache
6
6
  include Singleton
7
7
 
8
- #for testing
8
+ # Injectable backend.
9
9
  attr_writer :backend
10
10
 
11
11
  class << self
@@ -13,14 +13,25 @@ module AwsDevUtils
13
13
  def_delegators :fetch
14
14
  end
15
15
 
16
+ # Returns a value from the cache for the given key.
17
+ # If the key can't be found, the block will be run and its result returned and be set in the cache.
18
+ # @param key [Object]
19
+ # @param exp [Integer]
20
+ # @param block [block] - called with no arguments, and returns the new value for the cache (if no cached data is found).
21
+ # @return [Object] the value from the cache or the result of the block
16
22
  def fetch key, exp=60, &block
17
23
  get(key) or block.().tap {|x| set(key, x, exp)}
18
24
  end
19
25
 
26
+ # Get the value of key. If not found, returns nil
20
27
  def get key
21
28
  deserialize backend.get key.to_s rescue nil
22
29
  end
23
30
 
31
+ # Set key to hold the value and set key to timeout after the a given expiration time(in seconds).
32
+ # @param key [Object]
33
+ # @param value [Object]
34
+ # @param expiration [Time,Integer] - the key-value timeout
24
35
  def set key, value, expiration
25
36
  backend.set key.to_s, serialize(value), expiration rescue nil
26
37
  end
@@ -4,8 +4,7 @@ module AwsDevUtils
4
4
  class CacheWrapper
5
5
  include AwsDevUtils::Utils
6
6
 
7
- # Initialize a new CacheWrapper, Internal use only
8
- #
7
+ # Initialize a new CacheWrapper, internal use only.
9
8
  # @param client [Aws client, NextTokenWrapper, RetryWrapper]
10
9
  # @param exp [Integer] - the key-value timeout
11
10
  def initialize client, exp=60
@@ -2,19 +2,28 @@ module AwsDevUtils
2
2
  class ClientWrapper
3
3
  include AwsDevUtils::Utils
4
4
 
5
+ # Initialize a new ClientWrapper, internal use only
6
+ # @params [Seahorse::Client::Base] client
7
+ # @param [Hash] options
8
+ # @option options [String] next_token max number of requests
9
+ # @option options [String] retry max number of retries
10
+ # @option options [String] cache the key-value timeout
5
11
  def initialize client, options={}
6
12
  @client = client
7
13
  @options = options
8
14
  end
9
15
 
16
+ # @return ClientWrapper with next_token option
10
17
  def with_next_token max=100
11
18
  self.class.new(@client, @options.merge(next_token: max))
12
19
  end
13
20
 
21
+ # @return ClientWrapper with retry option
14
22
  def with_retry max=5
15
23
  self.class.new(@client, @options.merge(retry: max))
16
24
  end
17
25
 
26
+ # @return ClientWrapper with cache option
18
27
  def with_cache exp=60
19
28
  self.class.new(@client, @options.merge(cache: exp))
20
29
  end
@@ -1,10 +1,10 @@
1
1
  module AwsDevUtils
2
2
  class NextTokenWrapper
3
3
 
4
- # Initialize a new NextTokenWrapper
5
- # @params client - Aws client / CacheWrapper / RetryWrapper
6
- # @param [Integer] max - max number of requests
7
- def initialize client, max=100 #:nodoc:
4
+ # Initialize a new NextTokenWrapper, internal use only
5
+ # @params client [Aws client / NextTokenWrapper / RetryWrapper]
6
+ # @param max [Integer] - max number of requests
7
+ def initialize client, max=100
8
8
  @client = client
9
9
  @max = max
10
10
  end
@@ -1,6 +1,9 @@
1
1
  module AwsDevUtils
2
2
  class RetryWrapper
3
3
 
4
+ # Initialize a new RetryWrapper, internal use only
5
+ # @params client [Aws client, NextTokenWrapper, RetryWrapper]
6
+ # @param max_tries [Integer] - max number of retries
4
7
  def initialize client, max_tries=5
5
8
  @client = client
6
9
  @max_tries = max_tries
@@ -3,6 +3,8 @@ module AwsDevUtils
3
3
 
4
4
  module_function
5
5
 
6
+ # Transforms an object to a nested struct.
7
+ # @return [OpenStruct]
6
8
  def nested_struct obj
7
9
  case obj
8
10
  when Hash
@@ -22,6 +24,8 @@ module AwsDevUtils
22
24
  end
23
25
  end
24
26
 
27
+ # Transforms an object to a nested hash.
28
+ # @return [Hash]
25
29
  def nested_hash obj
26
30
  if obj.kind_of? Array
27
31
  obj.map(&method(__method__))
@@ -1,3 +1,3 @@
1
1
  module AwsDevUtils
2
- VERSION = '1.4.4'
2
+ VERSION = '1.4.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-dev-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infastructure
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2019-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core