initable 0.0.0 → 0.2.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: 11652b09ebedba190e0b35394028990c76e9102ab9f0a35f16d48af094cfeb74
4
- data.tar.gz: a92c36ccaa4ee2b6ee7cb8598017fb8a10c92769255196bf301df8594b6ec812
3
+ metadata.gz: 96778d9b0314485a1c240e2c5ef7867df42092d4f906e794ec54097de2c6de93
4
+ data.tar.gz: 6b3619194eb1d9767e80ad31e13a7037fe10542c7b497a14df77ad7f04dade71
5
5
  SHA512:
6
- metadata.gz: fce4f982b787297b4d392fab52a64fd77684b74516007f403badf86abaeea65cae9129c48f02b343ac3d57b0783731b36ff07ddc46762252eac9dea259e142ca
7
- data.tar.gz: 17ab62fe13848134324f536a8d4b0b867623d37c538aec81aa724b5ff7b9c51cb2137270681948895f72baf949ff33a5ef02a5fc342ce7691e70c388fb5d294f
6
+ metadata.gz: ddabf5ef26a500fd501f59a89a6a7dc370b00136206737a14f534ee72fb7dce5ce58848b7c03985952c66212e6d53cfa1ce8882acefd7d36ca23befb1f070acc
7
+ data.tar.gz: 65e7d06a70d8f00f24b5b3edc7b4ccaf6672e7a357533c38991f7f4ea1619c5a9411b673f26d95444ba5530642e03c1ed0a339d4eeba2bdd47091e4cd7c1252c
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -18,10 +18,11 @@ toc::[]
18
18
  == Features
19
19
 
20
20
  * Provides a Domain Specific Language (DSL) for initializing objects.
21
+ * Built atop the {marameters_link}.
21
22
  * Uses the same data structure as answered by {method_parameters_link}.
22
23
  * Adheres to the {barewords_link} pattern.
23
24
  * Reduces the amount of code necessary to implement an object.
24
- * Built atop the {marameters_link} gem.
25
+ * Pairs well with {infusible_link}.
25
26
 
26
27
  == Requirements
27
28
 
@@ -317,7 +318,7 @@ This is useful when needing to forward a block to the super class.
317
318
 
318
319
  === Defaults
319
320
 
320
- You've already seen that you can provide a third element for defaults with optional positional and keyword parameters. Sometimes, though, you might want to use a more complex object as a default (especially if you want the default to be lazy loaded/initialized). For those situations use a `Proc`. Example:
321
+ You've already seen you can provide a third element for defaults with optional positional and keyword parameters. Sometimes, though, you might want to use a more complex object as a default (especially if you want the default to be lazy loaded/initialized). For those situations use a `Proc`. Example:
321
322
 
322
323
  [source,ruby]
323
324
  ----
@@ -334,12 +335,11 @@ demo.new
334
335
 
335
336
  Notice, for the `one` optional positional parameter, we get a default value of `"One"` once evaluated. For the `two` optional keyword parameter, we get a new instance of `Object` as a default value.
336
337
 
337
- ⚠️ At the moment, there a few caveats to be aware of when using procs as defaults:
338
+ ⚠️ There a few caveats to be aware of when using defaults:
338
339
 
339
340
  * Use procs because lambdas will throw a `TypeError`.
340
- * Use procs _with no arguments_ because only the body of the `Proc` is meant to be parsed. Otherwise, you'll get an `ArgumentError`.
341
- * Ensure each parameter is defined on a distinct line because the body of the `Proc` is extracted at runtime from the source location of the `Proc`. The goal is to improve upon this more in the future.
342
- * Avoid using within an IRB session because each value will evaluate as `nil`.
341
+ * Use procs _with no arguments_ because only the body of the `Proc` is parsed. Otherwise, you'll get an `ArgumentError`.
342
+ * Ensure each parameter -- with a default -- is defined on a distinct line because the body of the `Proc` is extracted at runtime from the source location of the `Proc`. The goal is to improve upon this further once Ruby link:https://bugs.ruby-lang.org/issues/21005[adds] source location with line start, line end, column start, and column end information.
343
343
 
344
344
  === Barewords
345
345
 
@@ -640,6 +640,20 @@ child.new { "demo" }
640
640
 
641
641
  With blocks, you only have to name them in the `parent` and they will be forwarded by the child. Keep in mind that if you only need to pass the block to the parent but want to use a `block_given?` check before messaging the function in your parent class, then you don't need to use this gem for those situations.
642
642
 
643
+ === Infusible
644
+
645
+ This gem pairs well with the {infusible_link} gem and requires no additional effort on your part. In terms of style, stick with including Initiable before Infusible because you'll most likely be using Initable to define basic parameters while Infusible will be used to inject dependencies from your container. This way your parameters will read sequentially left-to-right or top-to-bottom when looking at the implementation which improves readability. Example:
646
+
647
+ [source,ruby]
648
+ ----
649
+ class Demo
650
+ include Initable[%i[req label]]
651
+ include Infusible[:logger]
652
+ end
653
+ ----
654
+
655
+ You can include Initiable and Infusible in any order, though. Lastly, as with all keyword parameters, make sure you don't define the same key for both or you'll have an order of operations issue where one key overrides the other.
656
+
643
657
  === Guidelines
644
658
 
645
659
  The following is worth adhering to:
data/initable.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "initable"
5
- spec.version = "0.0.0"
5
+ spec.version = "0.2.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/initable"
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
25
  spec.required_ruby_version = "~> 3.4"
26
- spec.add_dependency "marameters", "~> 4.0"
26
+ spec.add_dependency "marameters", "~> 4.1"
27
27
 
28
28
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
29
29
  spec.files = Dir["*.gemspec", "lib/**/*"]
@@ -50,13 +50,9 @@ module Initable
50
50
  end
51
51
 
52
52
  def define_readers ancestor
53
- (names - ancestor.names).each do |name|
54
- symbol = name.inspect
55
-
56
- instance_module.module_eval <<-READERS, __FILE__, __LINE__ + 1
57
- #{compute_scope} attr_reader #{symbol}
58
- READERS
59
- end
53
+ instance_module.module_eval <<-READERS, __FILE__, __LINE__ + 1
54
+ #{compute_scope} attr_reader(*#{names - ancestor.names})
55
+ READERS
60
56
  end
61
57
 
62
58
  def compute_scope = METHOD_SCOPES.include?(scope) ? scope : :private
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: initable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -34,7 +34,7 @@ cert_chain:
34
34
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
35
35
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
36
36
  -----END CERTIFICATE-----
37
- date: 2025-01-01 00:00:00.000000000 Z
37
+ date: 2025-02-05 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: marameters
@@ -42,14 +42,14 @@ dependencies:
42
42
  requirements:
43
43
  - - "~>"
44
44
  - !ruby/object:Gem::Version
45
- version: '4.0'
45
+ version: '4.1'
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: '4.0'
52
+ version: '4.1'
53
53
  email:
54
54
  - brooke@alchemists.io
55
55
  executables: []
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.6.2
91
+ rubygems_version: 3.6.3
92
92
  specification_version: 4
93
93
  summary: An automatic object initializer.
94
94
  test_files: []
metadata.gz.sig CHANGED
Binary file