marameters 0.8.0 → 0.10.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: 0656ba29b3d12d44f9f34ae3a012542dc3a274712d2cabf8ba153053d1491310
4
- data.tar.gz: 21e3a15d709561a6c30adb4a212b1193c0d45a2e0f783761719054412a014136
3
+ metadata.gz: '09f8116959180daa2b1ac61d0e8b92ba5e5859fc44cdadcef4aaa3686e15a5c6'
4
+ data.tar.gz: 3a87c1d82885b8390c17849c48a38ce4541f818a4ea3d51e4c223e449cd88e6f
5
5
  SHA512:
6
- metadata.gz: 152aa26bb96768bc363f55a7fa43b5aed99f08038ac1bbb4a943a1efdf8b5138ce214b6a4b8012f179f12d00894a44869df6d25d938521712de35a3ab2c6efbd
7
- data.tar.gz: 620bf72c7c8bbe25b48dc370cee7d3a0e1b03f5df8090c326bc760be1dfb400168d62dac304e55acded56f75da24ca821c4ce04fa9cfb2740ad749434de69fec
6
+ metadata.gz: 7f9c1d0796c5b84df75288678b3a4336c1878d4b449247bf161a8f0ebf09699462db385a43cbfdac11d0e08dc716afa8fc3cca5d1538f9421dfa601abbc85a43
7
+ data.tar.gz: a6d9ce536adcb82d3f2014d0187f1a3758e942ded308b585be347f0f0916e8a0f6f822dec8e79b0a522aad4da96e2fe4dc6a359bb695f5747cdeb2d2edf7e117
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -13,7 +13,7 @@ Marameters is a portmanteau (i.e. `[m]ethod + p[arameters] = marameters`) which
13
13
  * *Arguments*: Represents the _actual_ values passed to the method when messaged. Example: `demo 1, two: 2`.
14
14
 
15
15
  This gem will help you debug methods or aid your workflow when
16
- metaprogramming -- as used in the link:https://www.alchemists.io/projects/auto_injector[Auto Injector] gem -- when architecting more sophisticated applications.
16
+ metaprogramming -- as used in the link:https://www.alchemists.io/projects/infusible[Infusible] gem -- when architecting more sophisticated applications.
17
17
 
18
18
  toc::[]
19
19
 
@@ -153,7 +153,7 @@ probe.to_a # []
153
153
 
154
154
  === Categorizer
155
155
 
156
- The categorizer allows you to dynamically build positional, keyword, and block arguments for message passing. This is most valuable when you know the object, method, and arguments while also needing to assemble the arguments are in the right order. Here's a demonstration where {amazing_print_link} (i.e. `ap`) is used to format the output:
156
+ The categorizer allows you to dynamically build positional, keyword, and block arguments for message passing. This is most valuable when you know the object and method while needing to align the arguments in the right order. Here's a demonstration where {amazing_print_link} (i.e. `ap`) is used to format the output:
157
157
 
158
158
  [source,ruby]
159
159
  ----
@@ -207,7 +207,7 @@ Inspector.call [1, nil, nil, {four: 4}]
207
207
 
208
208
  When we step through the above implementation and output, we see the following unfold:
209
209
 
210
- . The `Demo` module allows us define a maximum set of parameters and then print the arguments received for inspection purposes.
210
+ . The `Demo` module allows us to define a maximum set of parameters and then print the arguments received for inspection purposes.
211
211
  . The `Inspector` module provides a wrapper around the `Categorizer` so we can conveniently pass in different arguments for experimentation purposes.
212
212
  . We pass in our arguments to `Inspector.call` where `nil` is used for optional arguments and hashes for keyword arguments.
213
213
  . Once inside `Inspector.call`, the `Categorizer` is initialized with the `Demo.test` method parameters.
@@ -248,7 +248,7 @@ Inspector.call [1, 2, [98, 99], {four: 4}, {five: 5}, {twenty: 20, thirty: 30},
248
248
  # 7. #<Proc:0x000000010a88cec0 (irb):1>
249
249
  ----
250
250
 
251
- Once again, it is important to keep in mind that the argument positions _must_ align with the parameter positions since the parameters are an array of elements too. For illustration purposes -- and using the above example -- we can compare the parameters to the arguments as follows:
251
+ Once again, it is important to keep in mind that the argument positions _must_ align with the parameter positions since the parameters are an array of elements too. For illustration purposes -- using the above example -- we can compare the parameters to the arguments as follows:
252
252
 
253
253
  [source,ruby]
254
254
  ----
@@ -280,10 +280,22 @@ ap arguments
280
280
 
281
281
  This also means that:
282
282
 
283
- * All positions much be filled if you want to supply arguments beyond the first couple of positions because everything is positional due to the nature of how link:https://rubyapi.org/o/method#method-i-parameters[Method#parameters] works. Use `nil` to fill an optional argument when you don't need it.
284
- * The `:rest` (single splat) argument must an array or `nil` if not present because even though it is _optional_, it is still _positional_.
283
+ * All positions must be filled if you want to supply arguments beyond the first couple of positions because everything is positional due to the nature of how link:https://rubyapi.org/o/method#method-i-parameters[Method#parameters] works. Use `nil` to fill an optional argument when you don't need it.
284
+ * The `:rest` (single splat) argument must be an array or `nil` if not present because even though it is _optional_, it is still _positional_.
285
285
  * The `:keyrest` (double splat) argument -- much like the `:rest` argument -- must be a hash or `nil` if not present.
286
286
 
287
+ Lastly, in all of the above examples, only an array of arguments has been used but you can pass in a single argument too (i.e. non-array). This is handy for method signatures which have only a single parameter or only use splats. Having to remember to wrap your argument in an array each time can get tedious so when _only_ a single argument is supplied, the categorizer will automatically cast the argument as an array. A good example of this use case is when using structs. Example:
288
+
289
+ [source,ruby]
290
+ ----
291
+ url = Struct.new :label, :url, keyword_init: true
292
+
293
+ Marameters.categorize(url.method(:new).parameters, {label: "Eaxmple", url: "https://example.com"})
294
+ .then { |splat| url.new(*splat.positionals, **splat.keywords) }
295
+
296
+ # Yields: #<struct label="Eaxmple", url="https://example.com">
297
+ ----
298
+
287
299
  For further details, please refer back to my {article_link} article mentioned in the _Requirements_ section.
288
300
 
289
301
  === Signature
@@ -371,6 +383,15 @@ puts Example.say "Hello"
371
383
 
372
384
  == Development
373
385
 
386
+ To contribute, run:
387
+
388
+ [source,bash]
389
+ ----
390
+ git clone https://github.com/bkuhlmann/marameters
391
+ cd marameters
392
+ bin/setup
393
+ ----
394
+
374
395
  You can also use the IRB console for direct access to all objects:
375
396
 
376
397
  [source,bash]
@@ -14,7 +14,7 @@ module Marameters
14
14
 
15
15
  def call arguments
16
16
  @record = model.new
17
- map arguments
17
+ map arguments.is_a?(Array) ? arguments : [arguments]
18
18
  record
19
19
  end
20
20
 
@@ -23,7 +23,13 @@ module Marameters
23
23
  attr_reader :parameters, :model, :record
24
24
 
25
25
  def map arguments
26
- parameters.each.with_index { |pair, index| filter pair, arguments[index] }
26
+ return record if arguments.empty?
27
+
28
+ size = arguments.size
29
+
30
+ parameters.each.with_index do |pair, index|
31
+ filter pair, arguments[index] if index < size
32
+ end
27
33
  end
28
34
 
29
35
  def filter pair, value
@@ -1,12 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "refinements/arrays"
4
-
5
3
  module Marameters
6
4
  # Provides information on a method's parameters.
7
5
  class Probe
8
- using Refinements::Arrays
9
-
10
6
  CATEGORIES = {
11
7
  positionals: %i[req opt],
12
8
  keywords: %i[keyreq key],
data/marameters.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "marameters"
5
- spec.version = "0.8.0"
5
+ spec.version = "0.10.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/marameters"
@@ -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.1"
26
- spec.add_dependency "refinements", "~> 9.6"
26
+ spec.add_dependency "refinements", "~> 9.7"
27
27
  spec.add_dependency "zeitwerk", "~> 2.6"
28
28
 
29
29
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
29
29
  RFE=
30
30
  -----END CERTIFICATE-----
31
- date: 2022-09-03 00:00:00.000000000 Z
31
+ date: 2022-10-22 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: refinements
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '9.6'
39
+ version: '9.7'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '9.6'
46
+ version: '9.7'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: zeitwerk
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.3.21
106
+ rubygems_version: 3.3.24
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Provides dynamic method parameter construction and deconstruction.
metadata.gz.sig CHANGED
Binary file