cloud_powers 0.2.7.9 → 0.2.7.10

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
  SHA1:
3
- metadata.gz: d3227c31d3bf9beee04672d4618bcfbe6ed1cc54
4
- data.tar.gz: 6dd0afd2c87f027ede8ae483f68e974070762e4c
3
+ metadata.gz: 157ca237f0e8a7f4a1500700f806c9ff015e26b7
4
+ data.tar.gz: 3af6b35eb9f76a8e2c0edb452598fd4f7e552db9
5
5
  SHA512:
6
- metadata.gz: 5c16e279244fcb90f80fe264a281865f0a6a21974523b922b178369f7e090c60d9a5fe8a85084053efcf58b2cedbad57453e5f5b617ded1df6ea72704cb46904
7
- data.tar.gz: 4bd3f8639837ab0fe2cc2f24b00f6dc4fb450d20b8a5fbbc4efb9b1546cfd282422caa2ba5b9b77a01dc4a30aabfea46b0f21aa77276db6399fdd4e6343efe85
6
+ metadata.gz: 2dcb1765d30f70a3f06007a15e44ffadef18997ad5655dc584f6ffe145c66f5b2992b9d9c0b578f9bd71c590c9083ddb84a3c281568926a003eef7b474dbf95a
7
+ data.tar.gz: c852d143ae51b4c8666cce7f3dace1747a6119d1ddcf324e4b4f4e6f8ce16f83e16f276b4715c174f1aa9cfc3a150f04cc8c2ea195410568bf2e577b9ce41c44
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloud_powers (0.2.7.9)
4
+ cloud_powers (0.2.7.10)
5
5
  activesupport-core-ext (~> 4)
6
6
  aws-sdk (~> 2)
7
7
  dotenv (~> 2.1)
@@ -16,6 +16,20 @@ module Smash
16
16
  include Smash::CloudPowers::Helper
17
17
  include Smash::CloudPowers::Storage
18
18
 
19
+ # Predicate method to return true for valid job titles and false for invalid ones
20
+ #
21
+ # Parameters
22
+ # * name +String+ (optional) - name of the task in snake_case
23
+ #
24
+ # Returns
25
+ # +Boolean+
26
+ #
27
+ # Notes
28
+ # * TODO: needs improvement
29
+ def approved_task?(name = nil)
30
+ ['demo', 'testinz'].include? to_snake(name)
31
+ end
32
+
19
33
  # responsible for sourcing, loading into the global namespace
20
34
  # and use of Ruby source code, through the +#new()+ method on
21
35
  # that class
@@ -38,7 +52,7 @@ module Smash
38
52
  # job.build('abc-1234', Aws::SQS::Message)
39
53
  # # => +ExampleTask:Object+
40
54
  def build(id, msg)
41
- body = JSON.parse(msg)
55
+ body = decipher_message(msg)
42
56
  begin
43
57
  task = body.delete('task')
44
58
  if approved_task? task
@@ -55,18 +69,44 @@ module Smash
55
69
  end
56
70
  end
57
71
 
58
- # Predicate method to return true for valid job titles and false for invalid ones
72
+ # Get the body of the message out from a few different types of objects.
73
+ # The idea is to allow JSON, a String or some object that responds to :body
74
+ # through while continually attempting to decipher other types of objects
75
+ # finally giving up. But wait, after it gives up, it just turns it into a
76
+ # Hash and assumes that the value is a Task name.
59
77
  #
60
78
  # Parameters
61
- # * name +String+ (optional) - name of the task in snake_case
79
+ # * msg +String+
62
80
  #
63
81
  # Returns
64
- # +Boolean+
82
+ # +Hash+
83
+ #
84
+ # Example
85
+ # # given hash_message = { task: 'example' }
86
+ # # givem json_message = "\{"task":"example"\}"
87
+ # # given message_with_body = <Object @body="stuff stuff stuff">
88
+ #
89
+ # decipher_message(hash_message)
90
+ # # => { task: 'example' }
91
+ # decipher_message(json_message)
92
+ # # => { task: 'example' }
93
+ # decipher_message(message_with_body)
94
+ # # => { task: 'example' }
95
+ # decipher_message('some ridiculous string')
96
+ # # => { task: 'some_ridiculous_string'}
65
97
  #
66
98
  # Notes
67
- # * TODO: needs improvement
68
- def approved_task?(name = nil)
69
- ['demo', 'testinz'].include? to_snake(name)
99
+ # See +#to_snake()+
100
+ def decipher_message(msg)
101
+ begin
102
+ if msg.respond_to? :body
103
+ decipher_message(msg.body)
104
+ else
105
+ msg.kind_of?(Hash) ? msg : JSON.parse(msg.to_s)
106
+ end
107
+ rescue Exception
108
+ { task: to_snake(msg.to_s) }
109
+ end
70
110
  end
71
111
  end
72
112
  end
@@ -1,3 +1,3 @@
1
1
  module CloudPowers
2
- VERSION = "0.2.7.9"
2
+ VERSION = "0.2.7.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_powers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7.9
4
+ version: 0.2.7.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Phillipps