etcher 2.0.0 → 2.1.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: 18c97ac57c0742fedf8872da7aa401ceae29552ccc9e78ce0d8df72fc8fff08c
4
- data.tar.gz: feb2442ddc16419bc49dc97ba1e449e226713d57a2c1fd6714e8592479faf636
3
+ metadata.gz: 34e559c63ed6f3baa580995e227f09113e26cacc8920a919f5d10912b4d1cad0
4
+ data.tar.gz: e23d9de0fffff7d2ae6835a0c6e38dbab5cfdc555839051544a9f24432b73884
5
5
  SHA512:
6
- metadata.gz: cd2eb81d5e6a950c8d2cc7205fa09d41608bf2a835e25aa13dc5bbbb9bf4f6a60eea36716d5a132047aba29290a3706c8b3b6b54c175df9f95d0e25943719d25
7
- data.tar.gz: af20a0db0eaefd28a6a69c1bf0193084ec841a1042cc6f842667c3cc2da803d064e244670429c30a621905615b4a6aee963cab081028b6d10d7b563444fa6969
6
+ metadata.gz: 5855391dea3b6fa69e206867a8f4b5b3c304e06902044cd70d01eea97dfcc4126bc505d2ea0e9c5424e1089caca8bf7d4ad3d340350a6a53a0d34e55cd4280eb
7
+ data.tar.gz: e4c23192f2f12a3b086a4dcfc796fa9be9b52c743583e39bcd241071e8e7d4dc487b2b1a47f37a2d31076efd62247d56a043d45c8e135100f2636b40052d2013
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -291,7 +291,22 @@ registry = Etcher::Registry[loaders: [MyLoader.new]]
291
291
  registry = Etcher::Registry.new.add_loader MyLoader.new
292
292
  ----
293
293
 
294
- There are a few guidelines to using them:
294
+ You can also remove a previously added loader by index:
295
+
296
+ [source,ruby]
297
+ ----
298
+ registry = Etcher::Registry.new
299
+
300
+ # Application
301
+ registry.add_loader MyLoader.new
302
+
303
+ # RSpec
304
+ registry.remove_loader 0
305
+ ----
306
+
307
+ The ability to remove a loader is especially handy in a testing environment where you might need to temporarily remove a loader or don't need a specific loader for testing purposes.
308
+
309
+ There are a few guidelines to using loaders:
295
310
 
296
311
  * All loaders must respond to `#call` with no arguments.
297
312
  * All loaders must answer either a success with attributes (i.e. `Success attributes`) or a failure with details about the failure (i.e. `Failure step: :load, constant: MyLoader, payload: "My error message.`)
@@ -464,6 +479,21 @@ registry = Etcher::Registry[transformers: [MyTransformer]]
464
479
  registry = Etcher::Registry.new.add_transformer MyTransformer
465
480
  ----
466
481
 
482
+ You can also remove a previously added transformer by index:
483
+
484
+ [source,ruby]
485
+ ----
486
+ registry = Etcher::Registry.new
487
+
488
+ # Application
489
+ registry.add_transformer MyTransformer
490
+
491
+ # RSpec
492
+ registry.remove_transformer 0
493
+ ----
494
+
495
+ The ability to remove a transformer is especially handy in a testing environment where you might need to temporarily remove a transformer or don't need a specific transformer for testing purposes.
496
+
467
497
  The guidelines for using transformers are:
468
498
 
469
499
  * They can be initialized with whatever requirements you need.
@@ -574,7 +604,7 @@ transformer.call({demo: "defined"})
574
604
 
575
605
  ==== Format
576
606
 
577
- Use `Etcher::Transformers::Format` to transform any key's value by using the configuration's existing attributes to format the value of a specific key using the {string_formats_link} Specification. Example:
607
+ Use `Etcher::Transformers::Format` to transform any key's value by using the configuration's existing attributes to format the value of a specific key using the {string_formats_link} Specification. To start, we'll use the same attributes for all examples:
578
608
 
579
609
  [source,ruby]
580
610
  ----
@@ -583,7 +613,12 @@ attributes = {
583
613
  project_name: "test",
584
614
  project_uri: "%<organization_uri>s/projects/%<project_name>s"
585
615
  }
616
+ ----
617
+
618
+ Using the above `attributes`, you'll get a `Success` when all required keys exist:
586
619
 
620
+ [source,ruby]
621
+ ----
587
622
  Etcher::Transformers::Format.new(:project_uri).call attributes
588
623
  # Success(
589
624
  {
@@ -592,9 +627,14 @@ Etcher::Transformers::Format.new(:project_uri).call attributes
592
627
  project_uri: "https://acme.io/projects/test"
593
628
  }
594
629
  )
630
+ ----
595
631
 
632
+ When some required keys are missing, you'll get a `Failure`:
633
+
634
+ [source,ruby]
635
+ ----
596
636
  attributes.delete :project_name
597
- transformer.call attributes
637
+ Etcher::Transformers::Format.new(:project_uri).call attributes
598
638
 
599
639
  # Failure(
600
640
  # {
@@ -605,6 +645,38 @@ transformer.call attributes
605
645
  # )
606
646
  ----
607
647
 
648
+ You can partially transform a value using _retainers_ and/or _mappings_ for situations where you need to format a value while preserving and/or remapping string specifiers for delayed formatting. Here's an example using a _retainer_ which preserves the `:project_name`.
649
+
650
+ [source,ruby]
651
+ ----
652
+ Etcher::Transformers::Format.new(:project_uri, :project_name).call attributes
653
+
654
+ # Success(
655
+ # {
656
+ # organization_uri: "https://acme.io",
657
+ # project_name: "test",
658
+ # project_uri: "https://acme.io/projects/%<project_name>s"
659
+ # }
660
+ # )
661
+ ----
662
+
663
+ Notice the `organization_uri` was formatted in the `project_uri` while the `project_name` was preserved. This allows you to format the `project_name` when you can supply the value later. Similarly, you can remap a string specifier. Example:
664
+
665
+ [source,ruby]
666
+ ----
667
+ Etcher::Transformers::Format.new(:project_uri, project_name: "%<id>s").call attributes
668
+
669
+ # Success(
670
+ # {
671
+ # organization_uri: "https://acme.io",
672
+ # project_name: "test",
673
+ # project_uri: "https://acme.io/projects/%<id>s"
674
+ # }
675
+ # )
676
+ ----
677
+
678
+ Notice the `organization_uri` was formatted in the `project_uri` (same as before) while the `project_name` was remapped as `%<id>s`. As shown mentioned earlier, this allows you to _delay_ supplying the `id` when you might not have a value for it yet.
679
+
608
680
  You can also, safely, transform a value which _doesn't_ have string specifiers:
609
681
 
610
682
  [source,ruby]
@@ -613,7 +685,7 @@ Etcher::Transformers::Format.new(:version).call(version: "1.2.3")
613
685
  # Success({:version=>"1.2.3"})
614
686
  ----
615
687
 
616
- Normally, you'd get a "too many arguments for format string" warning but this transformer detects and immediate skips formatting when no string specifiers are detected. This is handy for situations where your configuration supports values which may or may not need formatting.
688
+ Normally, you'd get a "too many arguments for format string" warning but this transformer detects and immediately skips formatting when no string specifiers are detected. This is handy for situations where your configuration supports values which may or may not need formatting.
617
689
 
618
690
  ==== Time
619
691
 
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 = "2.0.0"
5
+ spec.version = "2.1.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/etcher"
@@ -8,9 +8,10 @@ module Etcher
8
8
  class Format
9
9
  include Dry::Monads[:result]
10
10
 
11
- def initialize key, **pass_throughs
11
+ def initialize key, *retainers, **mappings
12
12
  @key = key
13
- @pass_throughs = pass_throughs
13
+ @retainers = retainers
14
+ @mappings = mappings
14
15
  @pattern = /%<.+>s/o
15
16
  end
16
17
 
@@ -29,7 +30,13 @@ module Etcher
29
30
 
30
31
  private
31
32
 
32
- attr_reader :key, :pass_throughs, :pattern
33
+ attr_reader :key, :retainers, :mappings, :pattern
34
+
35
+ def pass_throughs
36
+ retainers.each
37
+ .with_object({}) { |key, expansions| expansions[key] = "%<#{key}>s" }
38
+ .merge! mappings
39
+ end
33
40
  end
34
41
  end
35
42
  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: 2.0.0
4
+ version: 2.1.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-07-05 00:00:00.000000000 Z
38
+ date: 2024-07-10 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: cogger
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  requirements: []
191
- rubygems_version: 3.5.14
191
+ rubygems_version: 3.5.15
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: A monadic configuration loader, transformer, and validator.
metadata.gz.sig CHANGED
Binary file