marameters 0.8.0 → 0.9.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: b53c9a80f1845fabb688e43162c18519192414425ef6a5b2a4c16e2575d29f99
4
+ data.tar.gz: e49e58811bb7e32ec2c8bee2691b6d230be4dc0f18503b86f5cebdfa812033c6
5
5
  SHA512:
6
- metadata.gz: 152aa26bb96768bc363f55a7fa43b5aed99f08038ac1bbb4a943a1efdf8b5138ce214b6a4b8012f179f12d00894a44869df6d25d938521712de35a3ab2c6efbd
7
- data.tar.gz: 620bf72c7c8bbe25b48dc370cee7d3a0e1b03f5df8090c326bc760be1dfb400168d62dac304e55acded56f75da24ca821c4ce04fa9cfb2740ad749434de69fec
6
+ metadata.gz: c4763d0f9492fce3673c1803884ae5cc6d49e64957f35649c7b10045a9146fbabf513a64d21346fd3642df9e481ba4f12cb59fcc361bae5fae0eb0cb3b7cc7c4
7
+ data.tar.gz: 4c6ffd0555c7d563759d4c25eb880f44ae8d4158d0399520bcb1301d64709c67a88b7aeedea69b6485c9598430b94d2a7d58529001435e6721fe704de742a023
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
@@ -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.9.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/marameters"
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.9.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-09-08 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: refinements
metadata.gz.sig CHANGED
Binary file