etcher 0.3.0 → 0.4.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: bdae8d6e407c3a6d7f9c43c79be0f97040996c4460f726976931a0a395c6f0c5
4
- data.tar.gz: 0ff6f4e79245a0e14c4e7dc36672562b5ae7ea370dd9a9ce1dae0cc83ff950bc
3
+ metadata.gz: 83465fdb68775b51454d5acd2b480f3b7936600e850acc8e28c2c66de503beda
4
+ data.tar.gz: b7ae8ada93f9e1066bd2cb476235f9713c0dbc704f861f2609f0b766100a7e37
5
5
  SHA512:
6
- metadata.gz: e9cd8e067ab556f27a53804f18f389a41a3987f9e942dcfa471cfbc937fc4a2a353c3f6a0bf260daa91667906bdcd8e162d99133563a6386fa98c9e241f3174c
7
- data.tar.gz: 5feeefaa7b6216791071572592d69e93fcbd5de940ff36713c68fec83e368fa53374ab42b780748c26b08c8acc283dbe03ef77c0d2a45cf0ca379a992754db38
6
+ metadata.gz: 4cd47900eb5a8f0cebfcda8be36d629f5438dce7081bb24cd587c2abd48d669740f49b00457b92495c06ca2b94385e2a5b906382138ad06d9e480f35f974a786
7
+ data.tar.gz: 62b87168d7eb24dc6c9611c801b61f978e4e1ff52692604cc844811edbfa4c7c65f173dc880c629b913d709dcdcf671217b5b5f44e7d68febe43cfbd8adf1544
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -29,14 +29,14 @@ ____
29
29
  [Use] strong acid or mordant to cut into the unprotected parts of a metal surface to create a design in intaglio (incised) in the metal.
30
30
  ____
31
31
 
32
- By using Etcher, you have a reliable way to load default configurations (i.e. {environment_link}, {json_link}, {yaml_link}) which can be validated and turned into records (i.e. {hash_link}, {data_link}, {struct_link}) for consumption within your application. In other words, the ability to take primitive hashes and _etch_ them into a _frozen_ record with a nice interface that doesn't violate the {demeter_link}. This comes complete with transformations and validations all via a simple Object API. Finally, this pairs well with the {xdg_link}, {runcom_link}, and {sod_link} gems.
32
+ By using Etcher, you have a reliable way to load default configurations (i.e. {environment_link}, {json_link}, {yaml_link}) which can be validated and etched into _frozen_ records (i.e. {hash_link}, {data_link}, {struct_link}) for consumption within your application which doesn't violate the {demeter_link}. This comes complete with transformations and validations all via a simple Object API. Pairs well with the {xdg_link}, {runcom_link}, and {sod_link} gems.
33
33
 
34
34
  toc::[]
35
35
 
36
36
  == Features
37
37
 
38
- * Supports contracts which respond to `#call` to validate a {hash_link} before building the final record. This pairs well with the {dry_schema_link} and {dry_validation_link} gems.
39
- * Supports models which respond to `.[]` for consuming a splatted {hash_link} to instantiate new records. This pairs well with primitives such as: {hash_link}, {data_link}, and {struct_link}.
38
+ * Supports contracts which respond to `#call` to validate a {hash_link} before building the final record. Pairs well with the {dry_schema_link} and {dry_validation_link} gems.
39
+ * Supports models which respond to `.[]` for consuming a splatted {hash_link} to instantiate new records. Pairs well with primitives such as: {hash_link}, {data_link}, and {struct_link}.
40
40
  * Supports loading of default configurations from the {environment_link}, a {json_link} configuration, a {yaml_link} configuration, or anything that can answer a hash.
41
41
  * Supports multiple transformations which can process loaded configuration hashes and answer a transformed hash.
42
42
  * Supports {hash_link} overrides as a final customization which is handy for Command Line Interfaces (CLIs), as aided by {sod_link}, or anything that might require user input at runtime.
@@ -106,7 +106,10 @@ contract = Dry::Schema.Params do
106
106
  end
107
107
 
108
108
  model = Data.define :user, :home
109
- transformer = -> content { Dry::Monads::Success content.merge! user: content[:user].upcase }
109
+
110
+ transformer = lambda do |content, key = :user|
111
+ Dry::Monads::Success content.merge! key => content[key].upcase
112
+ end
110
113
 
111
114
  Etcher::Registry.new(contract:, model:, transformers: [transformer])
112
115
  .add_loader(Etcher::Loaders::Environment.new(%w[USER HOME]))
@@ -136,6 +139,8 @@ As hinted at above, the complete sequence of steps are performed in the order li
136
139
  . *Validate*: The contract is called to validate the content as previously loaded, overwritten, and transformed.
137
140
  . *Model*: The model consumes the content of the validated contract and creates a new record for you to use as needed.
138
141
 
142
+ 💡 The _override_ step comes after the _load_ step and before the _transform_ step because this gives you maximum flexibility to override any loaded/overwritten attributes while allowing you to transform any/all attributes based on whether they exist or not.
143
+
139
144
  You can use the above steps as a reference when using this gem. Each step is explained in greater detail below.
140
145
 
141
146
  === Registry
@@ -169,7 +174,7 @@ registry = Etcher::Registry.new
169
174
  .add_transformer(MyTransformer)
170
175
  ----
171
176
 
172
- 💡 Order matters so ensure you list your loaders and transformers in the order you want them to be processed.
177
+ 💡 Order matters so ensure you list your loaders and transformers in the order you want them processed.
173
178
 
174
179
  === Contracts
175
180
 
@@ -277,7 +282,7 @@ Notice we get an failure if all attributes are not provided but if we supply the
277
282
 
278
283
  === Loaders
279
284
 
280
- Loaders are a great way to load _default_ configuration information for your application which can be in multiple formats. Loaders can either be defined when creating a new registry instance or added after the fact. Here are a few examples:
285
+ Loaders are a great way to load a _default_ configuration for your application which can be in multiple formats. Loaders can either be defined when creating a new registry instance or added after the fact. Here are a few examples:
281
286
 
282
287
  [source,ruby]
283
288
  ----
@@ -373,7 +378,7 @@ If the file did exist and had content, you'd get a `Success` with a `Hash` of th
373
378
 
374
379
  ==== Custom
375
380
 
376
- You can always create your own loader if you don't need or want any of the default loaders provided for you. The only requirement is your loader _must_ respond to `#call` and answer a `Success` with a `Hash` for content which means you can use a class, method, lambda, or proc. Here's an example of creating a custom loader, registering, and using it:
381
+ You can always create your own loader if you don't need or want any of the default loaders provided for you. The only requirement is your loader _must_ respond to `#call` and answer a monad with a `Hash` for content which means you can use a class, method, lambda, or proc. Here's an example of creating a custom loader, registering, and using it:
377
382
 
378
383
  [source,ruby]
379
384
  ----
@@ -415,8 +420,9 @@ registry = Etcher::Registry.new.add_transformer MyTransformer
415
420
  Here are a few guidelines to using them:
416
421
 
417
422
  * They can be initialized with whatever requirements you might need.
418
- * They must respond to `#call` which takes a single argument (i.e. `content`) and answers a modified representation of this content as a `Success` with a `Hash` for content.
419
- * The `content` passed to your transformer will have symbolized keys.
423
+ * They must respond to `#call` which takes a required `content` positional argument and answers a modified representation of this content as a monad with a `Hash` for content.
424
+ * A second _optional_ positional `key` parameter should follow your `content` parameter when implementing your transformer. This allows you to quickly refactor the key later while also reducing key duplication throughout your implementation.
425
+ * The `content` passed to your transformer will have symbolized keys so you don't need to do this yourself.
420
426
 
421
427
  Here are a few examples of where you could go with this:
422
428
 
@@ -438,14 +444,19 @@ The following updates current time relative to when configuration was transforme
438
444
  ----
439
445
  require "dry/monads"
440
446
 
441
- CurrentTime = lambda do |content, at: Time.now|
442
- content[:at] = at
443
- Dry::Monads::Success content
447
+ CurrentTime = lambda do |content, key = :at, at: Time.now|
448
+ content.fetch(key) { at }
449
+ .then { |value| Dry::Monads::Success content.merge!(key => value) }
444
450
  end
445
451
 
446
452
  CurrentTime.call({})
447
-
448
453
  # Success({:at=>2023-04-23 15:22:23.746408 -0600})
454
+
455
+ CurrentTime.call({at: Time.utc(2023, 10, 15)})
456
+ # Success({:at=>2023-10-15 00:00:00 UTC})
457
+
458
+ CurrentTime.call({}, at: Time.utc(2023, 1, 10))
459
+ # Success({:at=>2023-01-10 00:00:00 UTC})
449
460
  ----
450
461
 
451
462
  The following obtains the current Git user's email address from the global Git configuration using the {gitt_link} gem.
@@ -456,15 +467,16 @@ require "dry/monads"
456
467
  require "gitt"
457
468
 
458
469
  class GitEmail
459
- def initialize git: Gitt::Repository.new
470
+ def initialize key = :author_email, git: Gitt::Repository.new
471
+ @key = key
460
472
  @git = git
461
473
  end
462
474
 
463
- def call(content) = git.get("user.email").fmap { |email| content[:author_email] = email }
475
+ def call(content) = git.get("user.email").fmap { |value| content[key] = value }
464
476
 
465
477
  private
466
478
 
467
- attr_reader :git
479
+ attr_reader :key, :git
468
480
  end
469
481
 
470
482
  GitEmail.new.call({})
@@ -493,7 +505,7 @@ etcher.call name: "test", label: "Test"
493
505
  # Success({:name=>"test", :label=>"Test"})
494
506
  ----
495
507
 
496
- These _overrides_ are applied _after_ all loaders are processed and _before_ any transformations. They are a nice way to deal with user input during runtime or provide any additional configuration not supplied by the loading of your default configuration.
508
+ Overrides are applied _after_ any loaders are processed and _before_ any transformations. They are a nice way to deal with user input during runtime or provide any additional configuration not supplied by the loading of your default configuration while still allowing you to transform them if desired.
497
509
 
498
510
  === Resolver
499
511
 
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 = "0.3.0"
5
+ spec.version = "0.4.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/etcher"
data/lib/etcher.rb CHANGED
@@ -3,8 +3,10 @@
3
3
  require "cogger"
4
4
  require "zeitwerk"
5
5
 
6
- Zeitwerk::Loader.for_gem.then do |loader|
6
+ Zeitwerk::Loader.new.then do |loader|
7
+ loader.push_dir __dir__
7
8
  loader.inflector.inflect "json" => "JSON", "yaml" => "YAML"
9
+ loader.tag = File.basename __FILE__, ".rb"
8
10
  loader.setup
9
11
  end
10
12
 
@@ -12,6 +14,8 @@ end
12
14
  module Etcher
13
15
  LOGGER = Cogger.new id: :etcher, formatter: :emoji
14
16
 
17
+ def self.loader(registry = Zeitwerk::Registry) = registry.loader_for __FILE__
18
+
15
19
  def self.new(...) = Builder.new(...)
16
20
 
17
21
  def self.call(registry = Registry.new, **) = Resolver.new(registry).call(**)
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: 0.3.0
4
+ version: 0.4.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: 2023-07-12 00:00:00.000000000 Z
38
+ date: 2023-10-01 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: cogger
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  requirements: []
185
- rubygems_version: 3.4.15
185
+ rubygems_version: 3.4.20
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: A monadic configuration loader, transformer, and validator.
metadata.gz.sig CHANGED
Binary file