yake 0.5.2 → 0.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05423d5da13bfc7484b2cf3f8a0a5c71534480b9925183b813bb8bdbaf564b1d
4
- data.tar.gz: 2ff53556d45a9dec3b909c4e711da615652127c9ce48f60516910944d44c3542
3
+ metadata.gz: d97ba087d51b600bac660504eacdd1d590f9acf5904baa20be399027ecbf85f2
4
+ data.tar.gz: 56d692bba03ba85e82d79fdceca350cb975654b13a6ba46441ce950e9c86b213
5
5
  SHA512:
6
- metadata.gz: 8b467a4358d9d73b603e16470b737a0a3c9bed0f9a14246ec035fe6cf99dba694d621d72d517e6959b8a5788fbc7a6fad72e6630fcf817fd1ca1f606e5558d78
7
- data.tar.gz: c9648172bae6dde99fad24d063670766d9722f428c51cc5e6e3aac034fb86050a1f5db17aae1d41243a6d6e368ff322076120a14da7926489eccc684ea907df7
6
+ metadata.gz: e707b8cf74c1cee8bd58e8345760a2680687296d9a5eb487b8f6320cf4b44b8817f2d281179cd4c20838eeb3c32f394e1a2ab77293999617b5a4fc9621ffca4e
7
+ data.tar.gz: bf1339315504d1e47a7158a7a99175bd147372231c44e9344ec989122dd43e448ab5f2b8d9fcb20f65bef3b2c2fea88800d8677e02adcbb515b9e8b5a5322b68
data/README.md CHANGED
@@ -67,11 +67,11 @@ gem install yake
67
67
 
68
68
  So why use `yake` for your Lambda functions?
69
69
 
70
- #### Event Logging
70
+ ### Event Logging
71
71
 
72
72
  By default, the `handler` function wraps its block in log lines formatted to match the style of Amazon's native Lambda logs sent to CloudWatch. Each invocation of the handler will log both the _input event_ and the _returned value_, prefixed with the ID of the request:
73
73
 
74
- ```
74
+ ```plaintext
75
75
  START RequestId: 149c500f-028a-4b57-8977-0ef568cf8caf Version: $LATEST
76
76
  INFO RequestId: 149c500f-028a-4b57-8977-0ef568cf8caf EVENT { … }
77
77
 
@@ -101,7 +101,7 @@ Fizz.new.logger == Yake.logger
101
101
  # => true
102
102
  ```
103
103
 
104
- #### API Routes
104
+ ### API Routes
105
105
 
106
106
  A common use of Lambda functions is as a proxy for API Gateway. Oftentimes users will deploy a single Lambda function to handle all requests coming from API Gateway.
107
107
 
@@ -168,14 +168,14 @@ Route an event to one of the declared routes:
168
168
  ```ruby
169
169
  handler :lambda_handler do |event|
170
170
  route event
171
- rescue Yake::UndeclaredRoute => err
171
+ rescue Yake::Errors::UndeclaredRoute => err
172
172
  respond 404, { message: err.message }.to_json
173
173
  rescue => err
174
174
  respond 500, { message: err.message }.to_json
175
175
  end
176
176
  ```
177
177
 
178
- #### Zero Dependencies
178
+ ### Zero Dependencies
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
 
@@ -189,7 +189,17 @@ Enable the helpers by requiring the `support` submodule:
189
189
  require 'yake/support'
190
190
  ```
191
191
 
192
- `Hash` transformations:
192
+ `Object` helpers:
193
+
194
+ ```ruby
195
+ MyObject.new.some_method
196
+ # => NoMethodError
197
+
198
+ MyObject.new.try(:some_method)
199
+ # => nil
200
+ ```
201
+
202
+ `Hash` helpers:
193
203
 
194
204
  ```ruby
195
205
  { fizz: 'buzz' }.encode64
@@ -198,6 +208,9 @@ require 'yake/support'
198
208
  { fizz: 'buzz' }.strict_encode64
199
209
  # => "eyJmaXp6IjoiYnV6eiJ9"
200
210
 
211
+ { fizz: { buzz: %w[jazz fuzz] } }.stringify_names
212
+ # => { "fizz" => { "buzz" => ["jazz", "fuzz"] } }
213
+
201
214
  { 'fizz' => { 'buzz' => %w[jazz fuzz] } }.symbolize_names
202
215
  # => { :fizz => { :buzz => ["jazz", "fuzz"] } }
203
216
 
@@ -205,7 +218,7 @@ require 'yake/support'
205
218
  # => "fizz=buzz"
206
219
  ```
207
220
 
208
- `Integer` transformations:
221
+ `Integer` helpers:
209
222
 
210
223
  ```ruby
211
224
  7.weeks
@@ -224,11 +237,16 @@ require 'yake/support'
224
237
  # => 2009-02-13 23:31:30 UTC
225
238
  ```
226
239
 
227
- `String` transformations:
240
+ `String` helpers:
228
241
 
229
242
  ```ruby
243
+ host = 'https://example.com/'
244
+ path = '/path/to/resource'
245
+ host / path
246
+ # => "https://example.com/path/to/resource"
247
+
230
248
  'snake_case_string'.camel_case
231
- # => SnakeCaseString
249
+ # => "SnakeCaseString"
232
250
 
233
251
  "Zml6eg==\n".decode64
234
252
  # => "fizz"
@@ -237,7 +255,7 @@ require 'yake/support'
237
255
  # => "Zml6eg==\n"
238
256
 
239
257
  'CamelCaseString'.snake_case
240
- # => 'camel_case_string'
258
+ # => "camel_case_string"
241
259
 
242
260
  'Zml6eg=='.strict_decode64
243
261
  # => "fizz"
@@ -252,17 +270,17 @@ require 'yake/support'
252
270
  # => { "fizz" => "buzz" }
253
271
  ```
254
272
 
255
- `Symbol` transformations
273
+ `Symbol` helpers
256
274
 
257
275
  ```ruby
258
276
  :snake_case_symbol.camel_case
259
277
  # => :SnakeCaseSymbol
260
278
 
261
279
  :CamelCaseSymbol.snake_case
262
- # => 'camel_case_symbol'
280
+ # => :camel_case_symbol
263
281
  ```
264
282
 
265
- `UTC` Time helper
283
+ `UTC` Time helpers
266
284
 
267
285
  ```ruby
268
286
  UTC.at 1234567890
data/lib/yake/support.rb CHANGED
@@ -4,7 +4,9 @@ require 'time'
4
4
 
5
5
  class Hash
6
6
  def encode64() to_json.encode64 end
7
+ def except(*keys) self.reject { |key,_| keys.include? key } end
7
8
  def strict_encode64() to_json.strict_encode64 end
9
+ def stringify_names() JSON.parse(to_json) end
8
10
  def symbolize_names() JSON.parse(to_json, symbolize_names: true) end
9
11
  def to_form() URI.encode_www_form(self) end
10
12
  end
@@ -24,6 +26,14 @@ class Integer
24
26
  alias :week :weeks
25
27
  end
26
28
 
29
+ class Object
30
+ def try(method, *args, **kwargs)
31
+ send(method, *args, **kwargs)
32
+ rescue
33
+ nil
34
+ end
35
+ end
36
+
27
37
  class String
28
38
  def /(path) File.join(self, path.to_s) end
29
39
  def camel_case() split(/_/).map(&:capitalize).join end
data/lib/yake/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yake
4
- VERSION = '0.5.2'
4
+ VERSION = '0.5.5'
5
5
  end
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.5.2
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Mancevice
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-05 00:00:00.000000000 Z
11
+ date: 2022-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: