yake 0.4.2 → 0.5.1
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.
- checksums.yaml +4 -4
- data/README.md +91 -1
- data/lib/yake/datadog.rb +17 -0
- data/lib/yake/support.rb +46 -0
- data/lib/yake/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3bcd08008b6aaa58e9015fd1b06cf8bf18f5c1bc1ecc7a272b375e0c8e5eea98
|
|
4
|
+
data.tar.gz: 632228bc6b6f69ba3a059e4df951571f3d0dbe1d0ee655982c94594010eff480
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6ba2c9ccaba3f6c9e9a567fcf2ab1332f98df97852bd96b16206fa46f0fe3f7873090f13e575475d9c68a04814af14e76eab574119f2893b0e6913f78dbdbde
|
|
7
|
+
data.tar.gz: 9c7072a8eee8193edf16a07f2557faae7d4cd1c671eea54713c8d1c9514071f4fc642e3203ee4c352cfa17f3f25bda59188e73aa64cd3462afca0539f757c5da
|
data/README.md
CHANGED
|
@@ -82,7 +82,7 @@ REPORT RequestId: 149c500f-028a-4b57-8977-0ef568cf8caf Duration: 43.97 ms Billed
|
|
|
82
82
|
|
|
83
83
|
Logging the request ID in this way makes gathering logs lines for a particular execution in CloudWatch much easier.
|
|
84
84
|
|
|
85
|
-
You can or disable the logger:
|
|
85
|
+
You can customize or disable the logger:
|
|
86
86
|
|
|
87
87
|
```ruby
|
|
88
88
|
logging :off # disables logging entirely
|
|
@@ -179,6 +179,96 @@ end
|
|
|
179
179
|
|
|
180
180
|
Finally, `yake` does not depend on any other gems, using the Ruby stdlib only. This helps keep your Lambda packages slim & speedy.
|
|
181
181
|
|
|
182
|
+
## Support Helpers
|
|
183
|
+
|
|
184
|
+
As of `v0.5`, `yake` comes with a support module for common transformations.
|
|
185
|
+
|
|
186
|
+
Enable the helpers by requiring the `support` submodule:
|
|
187
|
+
|
|
188
|
+
```ruby
|
|
189
|
+
require 'yake/support'
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`Hash` transformations:
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
{ fizz: 'buzz' }.encode64
|
|
196
|
+
# => "eyJmaXp6IjoiYnV6eiJ9\n"
|
|
197
|
+
|
|
198
|
+
{ fizz: 'buzz' }.strict_encode64
|
|
199
|
+
# => "eyJmaXp6IjoiYnV6eiJ9"
|
|
200
|
+
|
|
201
|
+
{ 'fizz' => { 'buzz' => %w[jazz fuzz] } }.symbolize_names
|
|
202
|
+
# => { :fizz => { :buzz => ["jazz", "fuzz"] } }
|
|
203
|
+
|
|
204
|
+
{ fizz: 'buzz' }.to_form
|
|
205
|
+
# => "fizz=buzz"
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`Integer` transformations:
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
7.days
|
|
212
|
+
# => 604800
|
|
213
|
+
|
|
214
|
+
7.hours
|
|
215
|
+
# => 25200
|
|
216
|
+
|
|
217
|
+
7.minutes
|
|
218
|
+
# => 420
|
|
219
|
+
|
|
220
|
+
1234567890.utc
|
|
221
|
+
# => 2009-02-13 23:31:30 UTC
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
`String` transformations:
|
|
225
|
+
|
|
226
|
+
```ruby
|
|
227
|
+
'snake_case_string'.camel_case
|
|
228
|
+
# => SnakeCaseString
|
|
229
|
+
|
|
230
|
+
"Zml6eg==\n".decode64
|
|
231
|
+
# => "fizz"
|
|
232
|
+
|
|
233
|
+
'fizz'.encode64
|
|
234
|
+
# => "Zml6eg==\n"
|
|
235
|
+
|
|
236
|
+
'CamelCaseString'.snake_case
|
|
237
|
+
# => 'camel_case_string'
|
|
238
|
+
|
|
239
|
+
'Zml6eg=='.strict_decode64
|
|
240
|
+
# => "fizz"
|
|
241
|
+
|
|
242
|
+
'fizz'.strict_encode64
|
|
243
|
+
# => "Zml6eg=="
|
|
244
|
+
|
|
245
|
+
'{"fizz":"buzz"}'.to_h_from_json
|
|
246
|
+
# => { "fizz" => "buzz" }
|
|
247
|
+
|
|
248
|
+
'fizz=buzz'.to_h_from_form
|
|
249
|
+
# => { "fizz" => "buzz" }
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`Symbol` transformations
|
|
253
|
+
|
|
254
|
+
```ruby
|
|
255
|
+
:snake_case_symbol.camel_case
|
|
256
|
+
# => :SnakeCaseSymbol
|
|
257
|
+
|
|
258
|
+
:CamelCaseSymbol.snake_case
|
|
259
|
+
# => 'camel_case_symbol'
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
`UTC` Time helper
|
|
263
|
+
|
|
264
|
+
```ruby
|
|
265
|
+
UTC.at 1234567890
|
|
266
|
+
# => 2009-02-13 23:31:30 UTC
|
|
267
|
+
|
|
268
|
+
UTC.now
|
|
269
|
+
# => 2022-02-26 13:57:07.860539 UTC
|
|
270
|
+
```
|
|
271
|
+
|
|
182
272
|
## Datadog Integration
|
|
183
273
|
|
|
184
274
|
As of `~> 0.4`, `yake` comes with a helper for writing Lambdas that integrate with Datadog's `datadog-ruby` gem.
|
data/lib/yake/datadog.rb
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
require 'logger'
|
|
2
3
|
|
|
3
4
|
require 'datadog/lambda'
|
|
4
5
|
require 'yake'
|
|
5
6
|
|
|
6
7
|
module Yake
|
|
7
8
|
module Datadog
|
|
9
|
+
class Formatter < ::Logger::Formatter
|
|
10
|
+
Format = "[%s] %s %s %s %s\n"
|
|
11
|
+
|
|
12
|
+
def call(severity, time, progname, msg)
|
|
13
|
+
Format % [
|
|
14
|
+
severity,
|
|
15
|
+
time.utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ'),
|
|
16
|
+
progname.nil? ? '-' : progname.split.last,
|
|
17
|
+
::Datadog.tracer.active_correlation,
|
|
18
|
+
msg2str(msg).strip,
|
|
19
|
+
]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
8
23
|
class MockContext < Struct.new(
|
|
9
24
|
:clock_diff,
|
|
10
25
|
:deadline_ms,
|
|
@@ -39,6 +54,8 @@ module Yake
|
|
|
39
54
|
end
|
|
40
55
|
end
|
|
41
56
|
end
|
|
57
|
+
|
|
58
|
+
logger.formatter = Datadog::Formatter.new
|
|
42
59
|
end
|
|
43
60
|
|
|
44
61
|
extend Yake::Datadog::DSL
|
data/lib/yake/support.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
class Hash
|
|
6
|
+
def encode64() to_json.encode64 end
|
|
7
|
+
def strict_encode64() to_json.strict_encode64 end
|
|
8
|
+
def symbolize_names() JSON.parse(to_json, symbolize_names: true) end
|
|
9
|
+
def to_form() URI.encode_www_form(self) end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class Integer
|
|
13
|
+
def weeks() days * 7 end
|
|
14
|
+
def days() hours * 24 end
|
|
15
|
+
def hours() minutes * 60 end
|
|
16
|
+
def minutes() seconds * 60 end
|
|
17
|
+
def seconds() self end
|
|
18
|
+
def utc() UTC.at(self) end
|
|
19
|
+
|
|
20
|
+
alias :second :seconds
|
|
21
|
+
alias :minute :minutes
|
|
22
|
+
alias :hour :hours
|
|
23
|
+
alias :day :days
|
|
24
|
+
alias :week :weeks
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class String
|
|
28
|
+
def camel_case() split(/_/).map(&:capitalize).join end
|
|
29
|
+
def decode64() Base64.decode64(self) end
|
|
30
|
+
def encode64() Base64.encode64(self) end
|
|
31
|
+
def snake_case() gsub(/([a-z])([A-Z])/, '\1_\2').downcase end
|
|
32
|
+
def strict_decode64() Base64.strict_decode64(self) end
|
|
33
|
+
def strict_encode64() Base64.strict_encode64(self) end
|
|
34
|
+
def to_h_from_json(**params) JSON.parse(self, **params) end
|
|
35
|
+
def to_h_from_form() URI.decode_www_form(self).to_h end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Symbol
|
|
39
|
+
def camel_case() to_s.camel_case.to_sym end
|
|
40
|
+
def snake_case() to_s.snake_case.to_sym end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class UTC < Time
|
|
44
|
+
def self.at(...) super.utc end
|
|
45
|
+
def self.now() super.utc end
|
|
46
|
+
end
|
data/lib/yake/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yake
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Mancevice
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-02-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|
|
@@ -25,6 +25,7 @@ files:
|
|
|
25
25
|
- lib/yake/dsl.rb
|
|
26
26
|
- lib/yake/errors.rb
|
|
27
27
|
- lib/yake/logger.rb
|
|
28
|
+
- lib/yake/support.rb
|
|
28
29
|
- lib/yake/version.rb
|
|
29
30
|
homepage: https://github.com/amancevice/yake
|
|
30
31
|
licenses:
|
|
@@ -38,14 +39,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
38
39
|
requirements:
|
|
39
40
|
- - ">="
|
|
40
41
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: 2.
|
|
42
|
+
version: 2.7.5
|
|
42
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
44
|
requirements:
|
|
44
45
|
- - ">="
|
|
45
46
|
- !ruby/object:Gem::Version
|
|
46
47
|
version: '0'
|
|
47
48
|
requirements: []
|
|
48
|
-
rubygems_version: 3.
|
|
49
|
+
rubygems_version: 3.3.7
|
|
49
50
|
signing_key:
|
|
50
51
|
specification_version: 4
|
|
51
52
|
summary: Rake-like DSL for declaring AWS Lambda function handlers
|