etcher 1.4.0 → 1.5.0

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
  SHA256:
3
- metadata.gz: 4a7381f41e75ad83f44a491f33f396be3ffb5b401a1a72fdcef2086984424fff
4
- data.tar.gz: '09b9c86d96af82fbc821e23c92e7966c97234e61625d3d23838471b930906629'
3
+ metadata.gz: 75820bd97bf8b61960802c1bb85cb91d5ad583778ca5860d4a887eea59f516a5
4
+ data.tar.gz: b83d2f5ed78a7ef5ba8b622b63855226413fb4a574cf44577a9f825509a33d82
5
5
  SHA512:
6
- metadata.gz: 3d3008b4581dfd66426ba9e9c2ed0158241d130c2e68372f124369dd42c5893fed86aff36fe9e1b14612fff2139f39cf7e4b07492b5faac13699a3f0d87f609c
7
- data.tar.gz: 885d3f522cefba39eeb8765fe671ea822d52edefc700d1633997825fd7cb61c834db7d6111cbd92881c5c9d232519e70bb4aa120027cc6ad432e82286d15fb99
6
+ metadata.gz: 891f2042e506243598e6545846ea5a4aeae21658315f5c25e32121c45279a64721cea0c275cf8ce7d723724007e108d3e09b7d538b6d28c7a049c7599da09c73
7
+ data.tar.gz: 0cb1f523435a2244994e88a9a51852f2a67b83c10bb3b817b147c9c80dd615bf777ecec069b2121af497dc225c6f1a032f53e856d41961145255b792eb70c80c
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -414,16 +414,15 @@ registry = Etcher::Registry[transformers: [MyTransformer]]
414
414
  registry = Etcher::Registry.new.add_transformer MyTransformer
415
415
  ----
416
416
 
417
- Here are a few guidelines to using them:
417
+ The guidelines for using transformers are:
418
418
 
419
- * They can be initialized with whatever requirements you might need.
419
+ * They can be initialized with whatever requirements you need.
420
420
  * They must respond to `#call` which takes a required `attributes` positional argument and answers a modified version of these attributes (`Hash`) wrapped as a monad.
421
- * A second _optional_ positional `key` parameter should follow your `attributes` parameter when implementing your transformer. This allows you to quickly refactor the key later while also reducing key duplication throughout your implementation.
421
+ * When using a proc/lambda, the first, _required_, parameter should be the `attributes` parameter followed by an _optional_ positional `key` parameter with a default value. This allows you to quickly refactor the key later while also reducing key duplication throughout your implementation.
422
+ * When using a class, the `key` should be your first positional parameter with a default value. Additional parameters can be supplied after if desired.
422
423
  * The `attributes` passed to your transformer will have symbolized keys so you don't need to transform them further.
423
424
 
424
- Here are a few examples of where you could go with this:
425
-
426
- The following capitalizes all values (which may or may not be good depending on your data structure).
425
+ For example, the following capitalizes all values (which may or may not be good depending on your data structure):
427
426
 
428
427
  [source,ruby]
429
428
  ----
@@ -435,28 +434,7 @@ Capitalize.call(name: "test")
435
434
  # Success({:name=>"Test"})
436
435
  ----
437
436
 
438
- The following updates current time relative to when configuration was transformed.
439
-
440
- [source,ruby]
441
- ----
442
- require "dry/monads"
443
-
444
- CurrentTime = lambda do |attributes, key = :at, at: Time.now|
445
- attributes.fetch(key) { at }
446
- .then { |value| Dry::Monads::Success attributes.merge!(key => value) }
447
- end
448
-
449
- CurrentTime.call({})
450
- # Success({:at=>2023-04-23 15:22:23.746408 -0600})
451
-
452
- CurrentTime.call({at: Time.utc(2023, 10, 15)})
453
- # Success({:at=>2023-10-15 00:00:00 UTC})
454
-
455
- CurrentTime.call({}, at: Time.utc(2023, 1, 10))
456
- # Success({:at=>2023-01-10 00:00:00 UTC})
457
- ----
458
-
459
- The following obtains the current Git user's email address from the global Git configuration using the {gitt_link} gem.
437
+ The following obtains the current Git user's email address from the global Git configuration using the {gitt_link} gem:
460
438
 
461
439
  [source,ruby]
462
440
  ----
@@ -485,11 +463,38 @@ To use all of the above, you'd only need to register and use them:
485
463
 
486
464
  [source,ruby]
487
465
  ----
488
- registry = Etcher::Registry[transformers: [Capitalize, CurrentTime, GitEmail.new]]
466
+ registry = Etcher::Registry[transformers: [Capitalize, GitEmail.new]]
489
467
  etcher = Etcher.new(registry)
490
468
  etcher.call
491
469
  ----
492
470
 
471
+ If you'd like prebuilt transformers, the following details what is supplied by this gem.
472
+
473
+ ==== Time
474
+
475
+ Use `Etcher::Transformers::Time` to transform the `loaded_at` key in your configuration when you want to know the current time at which the configuration was loaded. Handy for situations where you need to calculate relative time or format time based on when your configuration was loaded.
476
+
477
+ Even though `loaded_at` is the default key and `Time.now.utc` is the default fallback, you're not limited to using different keys and fallbacks. Example:
478
+
479
+ [source,ruby]
480
+ ----
481
+ transformer = Etcher::Transformers::Time.new
482
+ transformer.call({})
483
+ # Success({:loaded_at=>2024-05-23 22:18:27.92767 UTC})
484
+
485
+ transformer = Etcher::Transformers::Time.new :now
486
+ transformer.call({})
487
+ # Success({:now=>2024-05-23 22:18:49.93189 UTC})
488
+
489
+ transformer = Etcher::Transformers::Time.new :now, fallback: Time.utc(2000, 1, 1)
490
+ transformer.call({})
491
+ # Success({:now=>2000-01-01 00:00:00 UTC})
492
+
493
+ transformer = Etcher::Transformers::Time.new
494
+ transformer.call({loaded_at: Time.utc(2000, 1, 1)})
495
+ # Success({:loaded_at=>2000-01-01 00:00:00 UTC})
496
+ ----
497
+
493
498
  === Overrides
494
499
 
495
500
  Overrides are what you pass to the Etcher instance when called. Example:
data/etcher.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "etcher"
5
- spec.version = "1.4.0"
5
+ spec.version = "1.5.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/etcher"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/monads"
4
+
5
+ module Etcher
6
+ module Transformers
7
+ # Conditionally transforms current time for key.
8
+ class Time
9
+ include Dry::Monads[:result]
10
+
11
+ def initialize key = :loaded_at, fallback: ::Time.now.utc
12
+ @key = key
13
+ @fallback = fallback
14
+ end
15
+
16
+ def call attributes
17
+ attributes.fetch(key) { fallback }
18
+ .then { |value| Success attributes.merge!(key => value) }
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :key, :fallback
24
+ end
25
+ end
26
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2024-05-11 00:00:00.000000000 Z
38
+ date: 2024-05-23 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: cogger
@@ -155,6 +155,7 @@ files:
155
155
  - lib/etcher/loaders/yaml.rb
156
156
  - lib/etcher/registry.rb
157
157
  - lib/etcher/resolver.rb
158
+ - lib/etcher/transformers/time.rb
158
159
  - lib/etcher/types.rb
159
160
  homepage: https://alchemists.io/projects/etcher
160
161
  licenses:
metadata.gz.sig CHANGED
Binary file