aws-cache 0.0.03 → 0.0.04

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/aws-cache.rb +15 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTJjMThiMGIzYzE3NDE0ZWI0OGU1ODM3Yjg0YTVmYmNiNTY1YzUxMQ==
4
+ NWExNjliYjZjZmViNDU2MmJiNmJlZDA4OGNmYTlkMWIyMWVjZDk0MQ==
5
5
  data.tar.gz: !binary |-
6
- YThiMjI0NDdkNzdlMDUxMWYzNWQ2YThiZmJiMzZmOTgwZDQwZmZjOQ==
6
+ Njk1ZmYxMjgzYjQ5M2IyMWY0OGUxOTNkMzIzMGZkM2I1ZDcwMTFlZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjI2OWY4YTg5MDJlYThkNDAxZjk4Zjk1Zjc3ZjNmMDg5NDAyZDUyMTA0YWZl
10
- NjdkMDllMDQ1YWEyZjlmOTkzZTIyNzJjY2E4ODI0NzE5ZGFiYjM1Zjg2Nzg0
11
- NjQ2YTUyNDI3OWQ3ZmNmY2I3NGJiYThiMjdkNTBiZDc3ZjgxOGQ=
9
+ YzFjYzZiNzVlN2Y1NzhjZWQ1ZjE1MzE1M2MzMDk0MjIwNTAzZTBhMTZlNDBk
10
+ MmFkODAzYTY2MzAwZDMzOGUyYzkwNDcyYjBkYjI1ZWJlYjdhYzUwMGQ3Y2Mx
11
+ NGQxMDQ0YmU5MTYxYTI2ZDdhNjc0ZTc2YjAyYzE4MDJmZGI0ZmU=
12
12
  data.tar.gz: !binary |-
13
- YjU2ZGIxNmY1ODExN2ZhNmJhOGUwMjUxODFkZDQ2NTMxNjkzN2E2Yzg5NzY5
14
- NmRjM2NkZTE3MWM3MmZlMTQyZTc5ZTUwNzZjYWFlMGYwMWE4OGYwODI2Yjhh
15
- Nzg3Y2JlNWNmMzhjYTM0NzUwYjBiZTIxOWFhMmYyNjQ4ZmEzOGY=
13
+ MGQzOTA1NjcyZWY2NDZmYmVlODgzYWE2OGZlNzcyODFhZDIxYjRiOWZkNjZh
14
+ OGJkZGNjNTg0ZDNhZGFjMGFkMjk1OTczYmY0NzIzMDRjYzY2ZGZkMGE1MTY4
15
+ ZTE4NjRhMzBkNjM2MWI5YjcyNjhmOWQxYjJkMjFlOTcyZDY3MDc=
@@ -2,6 +2,7 @@ require 'redis'
2
2
  require 'json'
3
3
  require 'aws-sdk'
4
4
  require 'yaml'
5
+ require 'pry'
5
6
 
6
7
  class AwsCache
7
8
  # Please follow semantic versioning (semver.org).
@@ -43,7 +44,7 @@ class AwsCache
43
44
  instances = self.ec2_instances
44
45
  stack_instances = {}
45
46
  instances.each do |id, instance|
46
- if stack_name == optional_element(instance, [':tags','StackName',':value'], '')
47
+ if stack_name == optional_element(instance, [:tags,'StackName',:value], '')
47
48
  stack_instances[id] = instance
48
49
  end
49
50
  end
@@ -75,7 +76,7 @@ class AwsCache
75
76
  groups = self.auto_scaling_groups
76
77
  stack_groups = {}
77
78
  groups.each do |name, group|
78
- if stack_name == optional_element(group, [':tags','StackName',':value'], '')
79
+ if stack_name == optional_element(group, [:tags,'StackName',:value], '')
79
80
  stack_groups[name] = group
80
81
  end
81
82
  end
@@ -152,7 +153,7 @@ class AwsCache
152
153
  private
153
154
  def optional_element(hash, keys, default=nil)
154
155
  keys.each do |key|
155
- if !hash.is_a?(Hash) || !hash.has_key?(key)
156
+ if !has_key?(hash, key)
156
157
  return default
157
158
  end
158
159
  hash = hash[key]
@@ -160,6 +161,17 @@ class AwsCache
160
161
  return hash
161
162
  end
162
163
 
164
+ def has_key?(hash_or_struct, key)
165
+ hos = hash_or_struct
166
+ if hos.is_a?(Hash) && hos.has_key?(key)
167
+ return true
168
+ end
169
+ if hos.is_a?(Struct) && hos.members.any? { |m| m == key }
170
+ return true
171
+ end
172
+ return false
173
+ end
174
+
163
175
  def cache_get(key, ttl)
164
176
  vkey = "#{key}_#{@keyspace}"
165
177
  hash = @redis.get(vkey)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.03
4
+ version: 0.0.04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen J. Smith