marameters 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +66 -68
- data/lib/marameters/{analyzer.rb → probe.rb} +2 -2
- data/lib/marameters/signature.rb +2 -0
- data/marameters.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +14 -14
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 832b6f5bce93dd251a0e1972c9e4ef234237dc1d1e94f6b8ca15814dec7ddc00
|
4
|
+
data.tar.gz: 23c459d6e85fa64da272f5c9b319084f188c31d0360856be9826a92f59b619d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0338c575983adaff7b72af01ddc941ba2084b095f073992e853c740ac2aac70f8c4f3eaff9cea4001802240393e52b0a6cceb00ac3d20b47eda320591546e7b7'
|
7
|
+
data.tar.gz: 9bddaf3365b3b3d60f766479a036d754f6323082d606a1120a99343145858ba92436177236bf6f1cb6901b810bba55184ff0512262061fe25d58cf3db36a3663
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
= Marameters
|
6
6
|
|
7
|
-
Marameters is
|
8
|
-
|
9
|
-
|
7
|
+
Marameters is a portmanteau (i.e. `[m]ethod + p[arameters] = marameters`) which is designed to
|
8
|
+
provide additional insight and diagnostics to method parameters. For context, the difference between
|
9
|
+
a method's parameters and arguments is:
|
10
10
|
|
11
11
|
* *Parameters*: Represents the _expected_ values to be passed to a method when
|
12
12
|
messaged as defined when the method is implemented. Example: `def demo(one, two: nil)`.
|
@@ -21,7 +21,6 @@ toc::[]
|
|
21
21
|
|
22
22
|
== Features
|
23
23
|
|
24
|
-
* Provides a core object as a primary interface.
|
25
24
|
* Provides specialized objects for keyword, positional, and splatted parameters.
|
26
25
|
|
27
26
|
== Requirements
|
@@ -48,14 +47,14 @@ gem "marameters"
|
|
48
47
|
|
49
48
|
There are two main objects you'll want to interact with:
|
50
49
|
|
51
|
-
* *
|
52
|
-
* *Signature*: Allows you to dynamically build a method signature.
|
50
|
+
* *Marameters::Probe*: Allows you to analyze a method's parameters.
|
51
|
+
* *Marameters::Signature*: Allows you to dynamically build a method signature from raw parameters.
|
53
52
|
|
54
53
|
Both of these objects are meant to serve as building blocks to more complex architectures.
|
55
54
|
|
56
|
-
===
|
55
|
+
=== Probe
|
57
56
|
|
58
|
-
To understand how to
|
57
|
+
To understand how to analyze a method's parameters, consider the following demonstration class:
|
59
58
|
|
60
59
|
[source,ruby]
|
61
60
|
----
|
@@ -76,64 +75,64 @@ class Demo
|
|
76
75
|
end
|
77
76
|
----
|
78
77
|
|
79
|
-
You can then
|
78
|
+
You can then probe the `#all` method's parameters as follows:
|
80
79
|
|
81
80
|
[source,ruby]
|
82
81
|
----
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
----
|
104
|
-
|
105
|
-
In contrast the above, we can also
|
106
|
-
|
82
|
+
probe = Marameters::Probe.new Demo.instance_method(:all).parameters
|
83
|
+
|
84
|
+
probe.block # :seven
|
85
|
+
probe.block? # true
|
86
|
+
probe.empty? # false
|
87
|
+
probe.keywords # [:four, :five]
|
88
|
+
probe.keywords? # true
|
89
|
+
probe.kind?(:keyrest) # true
|
90
|
+
probe.kinds # [:req, :opt, :rest, :keyreq, :key, :keyrest, :block]
|
91
|
+
probe.name?(:three) # true
|
92
|
+
probe.names # [:one, :two, :three, :four, :five, :six, :seven]
|
93
|
+
probe.only_bare_splats? # false
|
94
|
+
probe.only_double_splats? # false
|
95
|
+
probe.only_single_splats? # false
|
96
|
+
probe.positionals # [:one, :two]
|
97
|
+
probe.positionals? # true
|
98
|
+
probe.splats # [:three, :six]
|
99
|
+
probe.splats? # true
|
100
|
+
probe.to_a # [[:req, :one], [:opt, :two], [:rest, :three], [:keyreq, :four], [:key, :five], [:keyrest, :six], [:block, :seven]]
|
101
|
+
probe.to_h # {:req=>:one, :opt=>:two, :rest=>:three, :keyreq=>:four, :key=>:five, :keyrest=>:six, :block=>:seven}
|
102
|
+
----
|
103
|
+
|
104
|
+
In contrast the above, we can also probe the `#none` method which has no parameters for a completely
|
105
|
+
different result:
|
107
106
|
|
108
107
|
[source,ruby]
|
109
108
|
----
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
109
|
+
probe = Marameters::Probe.new Demo.instance_method(:none).parameters
|
110
|
+
|
111
|
+
probe.block # nil
|
112
|
+
probe.block? # false
|
113
|
+
probe.empty? # true
|
114
|
+
probe.keywords # []
|
115
|
+
probe.keywords? # false
|
116
|
+
probe.kind?(:req) # true
|
117
|
+
probe.kinds # []
|
118
|
+
probe.name?(:three) # false
|
119
|
+
probe.names # []
|
120
|
+
probe.only_bare_splats? # false
|
121
|
+
probe.only_double_splats? # false
|
122
|
+
probe.only_single_splats? # false
|
123
|
+
probe.positionals # []
|
124
|
+
probe.positionals? # false
|
125
|
+
probe.splats # []
|
126
|
+
probe.splats? # false
|
127
|
+
probe.to_a # []
|
128
|
+
probe.to_h # {}
|
130
129
|
----
|
131
130
|
|
132
131
|
=== Signature
|
133
132
|
|
134
|
-
The signature class is the opposite of the
|
135
|
-
|
136
|
-
|
133
|
+
The signature class is the opposite of the probe in that you want to feed it parameters for turning
|
134
|
+
into a method signature. This is useful when dynamically building method signatures or using the
|
135
|
+
same signature when metaprogramming multiple methods.
|
137
136
|
|
138
137
|
The following demonstrates how you might construct a method signature with all possible parameters:
|
139
138
|
|
@@ -155,8 +154,8 @@ puts signature
|
|
155
154
|
# one, two = 2, *three, four:, five: 5, **six, &seven
|
156
155
|
----
|
157
156
|
|
158
|
-
You'll notice that the parameters
|
159
|
-
easier to write a hash than a double nested array as normally produced by the
|
157
|
+
You'll notice that the parameters are a hash _and_ some values can be tuples. The reason is that
|
158
|
+
it's easier to write a hash than a double nested array as normally produced by the probe or directly
|
160
159
|
from `Method#parameters`. The optional positional and keyword parameters use tuples because you
|
161
160
|
might want to supply a default value and this provides a way for you to do that with minimal syntax.
|
162
161
|
This can be demonstrated further by using optional keywords (same applies for optional positionals):
|
@@ -184,15 +183,16 @@ puts Marameters::Signature.new({key: [:demo, "*Object.new"]})
|
|
184
183
|
# demo: Object.new
|
185
184
|
----
|
186
185
|
|
187
|
-
In the case of object dependencies you need to wrap these in a string _and_ prefix them with a star
|
188
|
-
(`*`) so the signature builder won't confuse
|
189
|
-
|
186
|
+
In the case of object dependencies, you need to wrap these in a string _and_ prefix them with a star
|
187
|
+
(`*`) so the signature builder won't confuse them as normal strings. There are two reasons why this
|
188
|
+
is important:
|
190
189
|
|
191
|
-
* The star (`*`) signifies
|
192
|
-
|
190
|
+
* The star (`*`) signifies you want an object to be passed through without further processing while
|
191
|
+
also not being confused as a normal string.
|
193
192
|
* Objects wrapped as strings allows your dependency to be lazy loaded. Otherwise, if `Object.new`
|
194
|
-
was pass directly, you'd be passing the evaluated instance (i.e.
|
195
|
-
which is not what you want until much later when your method is
|
193
|
+
was pass in directly, you'd be passing the evaluated instance (i.e.
|
194
|
+
`#<Object:0x0000000107df4028>`) which is not what you want until much later when your method is
|
195
|
+
defined.
|
196
196
|
|
197
197
|
When you put all of this together, you can dynamically build a method as follows:
|
198
198
|
|
@@ -202,9 +202,7 @@ signature = Marameters::Signature.new({opt: [:text, "This is a test."]})
|
|
202
202
|
|
203
203
|
Example = Module.new do
|
204
204
|
module_eval <<~DEFINITION, __FILE__, __LINE__ + 1
|
205
|
-
def self.say
|
206
|
-
text
|
207
|
-
end
|
205
|
+
def self.say(#{signature}) = text
|
208
206
|
DEFINITION
|
209
207
|
end
|
210
208
|
|
data/lib/marameters/signature.rb
CHANGED
data/marameters.gemspec
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -10,9 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
MIIC/
|
14
|
-
|
15
|
-
|
13
|
+
MIIC/jCCAeagAwIBAgIBBTANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
|
14
|
+
a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMjAzMTkxNzI0MzJaFw0yMzAzMTkx
|
15
|
+
NzI0MzJaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
|
16
16
|
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6l1qpXTiomH1RfMRloyw7MiE
|
17
17
|
xyVx/x8Yc3EupdH7uhNaTXQGyORN6aOY//1QXXMHIZ9tW74nZLhesWMSUMYy0XhB
|
18
18
|
brs+KkurHnc9FnEJAbG7ebGvl/ncqZt72nQvaxpDxvuCBHgJAz+8i5wl6FhLw+oT
|
@@ -20,15 +20,15 @@ cert_chain:
|
|
20
20
|
D5vkU0YlAm1r98BymuJlcQ1qdkVEI1d48ph4kcS0S0nv1RiuyVb6TCAR3Nu3VaVq
|
21
21
|
3fPzZKJLZBx67UvXdbdicWPiUR75elI4PXpLIic3xytaF52ZJYyKZCNZJhNwfQID
|
22
22
|
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0nzow9vc
|
23
|
-
2CdikiiE3fJhP/
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAJbbNyWzFjqUNVPPCUCo
|
24
|
+
IMrhDa9xf1xkORXNYYbmXgoxRy/KyNbUr+jgEEoWJAm9GXlcqxxWAUI6pK/i4/Qi
|
25
|
+
X6rPFEFmeObDOHNvuqy8Hd6AYsu+kP94U/KJhe9wnWGMmGoNKJNU3EkW3jM/osSl
|
26
|
+
+JRxiH5t4WtnDiVyoYl5nYC02rYdjJkG6VMxDymXTqn7u6HhYgZkGujq1UPar8x2
|
27
|
+
hNIWJblDKKSu7hA2d6+kUthuYo13o1sg1Da/AEDg0hoZSUvhqDEF5Hy232qb3pDt
|
28
|
+
CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
|
29
|
+
RFE=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date: 2022-
|
31
|
+
date: 2022-04-07 00:00:00.000000000 Z
|
32
32
|
dependencies:
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: refinements
|
@@ -70,9 +70,9 @@ files:
|
|
70
70
|
- LICENSE.adoc
|
71
71
|
- README.adoc
|
72
72
|
- lib/marameters.rb
|
73
|
-
- lib/marameters/analyzer.rb
|
74
73
|
- lib/marameters/builder.rb
|
75
74
|
- lib/marameters/defaulter.rb
|
75
|
+
- lib/marameters/probe.rb
|
76
76
|
- lib/marameters/signature.rb
|
77
77
|
- marameters.gemspec
|
78
78
|
homepage: https://www.alchemists.io/projects/marameters
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.3.
|
103
|
+
rubygems_version: 3.3.10
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Provides dynamic method parameter construction and deconstruction.
|
metadata.gz.sig
CHANGED
Binary file
|