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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cloud_powers/delegator.rb +47 -7
- data/lib/cloud_powers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 157ca237f0e8a7f4a1500700f806c9ff015e26b7
|
4
|
+
data.tar.gz: 3af6b35eb9f76a8e2c0edb452598fd4f7e552db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dcb1765d30f70a3f06007a15e44ffadef18997ad5655dc584f6ffe145c66f5b2992b9d9c0b578f9bd71c590c9083ddb84a3c281568926a003eef7b474dbf95a
|
7
|
+
data.tar.gz: c852d143ae51b4c8666cce7f3dace1747a6119d1ddcf324e4b4f4e6f8ce16f83e16f276b4715c174f1aa9cfc3a150f04cc8c2ea195410568bf2e577b9ce41c44
|
data/Gemfile.lock
CHANGED
@@ -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 =
|
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
|
-
#
|
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
|
-
# *
|
79
|
+
# * msg +String+
|
62
80
|
#
|
63
81
|
# Returns
|
64
|
-
# +
|
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
|
-
#
|
68
|
-
def
|
69
|
-
|
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
|
data/lib/cloud_powers/version.rb
CHANGED