marameters 0.2.0 → 0.3.2

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: a3daee40e52b7df55680618be8c5a37a6a62c3ca7f62b88128fbc724f4222c50
4
- data.tar.gz: 3b4d527a40fc8ed6500faea3e6676b45be484a2fb9288b5e79ee38684ac0bec0
3
+ metadata.gz: 5bbbeb8cec07a943748c7a1c416c28da1db45c1d5f8ad3b54217a478306ab35b
4
+ data.tar.gz: 58f3c784e590fca8854f7bd38e2392b561863f0222c78bda07866cebce8ad354
5
5
  SHA512:
6
- metadata.gz: 459d04fcc654dcf3ef58d23dfaaff01f5df52e0ffbb8d670cb0d1a9f59f10f91d0e9ff424e5871c9e892a1ba7f2b4cbdb236a287e3b3ffbdf32a1e56de9b5f97
7
- data.tar.gz: 92df818d39aeacd231721b69299e0e23705b0f889db54360fefd0f269355fcbf40499b62c59bfc30a22b99dac39874b8a168c381e825ae4b2891a18b6fd9f53f
6
+ metadata.gz: 38871127b3e1c65c8c41a2fc899fff2bf79d5a3ad5c8d92b1de964cce7f0a72295929d43e917671be38c73bf361bdf7a706602204f7fc5117204a4433284f5fb
7
+ data.tar.gz: 5f452fcbf9ed4a1badb37e4e00a168d13381a04171c1ebb6154afb4503ebd2f67526e605da8fbce924ab9ea08ebe839b6d7e4edef22e1fad0988f87eb96cbc90
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 short for method parameters (i.e. `[m]ethod + p[arameters] = marameters`) which is
8
- designed to provide additional insight and diagnostics to method parameters. For context, the
9
- difference between a method's parameters and arguments is:
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
- * *Analyzer*: Allows you to analyze a method's parameters.
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
- === Analyzer
55
+ === Probe
57
56
 
58
- To understand how to _analyze_ a method's parameters, consider the following demonstration class:
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 analyze the `#all` method's parameters as follows:
78
+ You can then probe the `#all` method's parameters as follows:
80
79
 
81
80
  [source,ruby]
82
81
  ----
83
- analyzer = Marameters::Analyzer.new Demo.instance_method(:all).parameters
84
-
85
- analyzer.block # :seven
86
- analyzer.block? # true
87
- analyzer.empty? # false
88
- analyzer.keywords # [:four, :five]
89
- analyzer.keywords? # true
90
- analyzer.kind?(:keyrest) # true
91
- analyzer.kinds # [:req, :opt, :rest, :keyreq, :key, :keyrest, :block]
92
- analyzer.name?(:three) # true
93
- analyzer.names # [:one, :two, :three, :four, :five, :six, :seven]
94
- analyzer.only_bare_splats? # false
95
- analyzer.only_double_splats? # false
96
- analyzer.only_single_splats? # false
97
- analyzer.positionals # [:one, :two]
98
- analyzer.positionals? # true
99
- analyzer.splats # [:three, :six]
100
- analyzer.splats? # true
101
- analyzer.to_a # [[:req, :one], [:opt, :two], [:rest, :three], [:keyreq, :four], [:key, :five], [:keyrest, :six], [:block, :seven]]
102
- analyzer.to_h # {:req=>:one, :opt=>:two, :rest=>:three, :keyreq=>:four, :key=>:five, :keyrest=>:six, :block=>:seven}
103
- ----
104
-
105
- In contrast the above, we can also analyze the `#none` method which has no parameters for a
106
- completely different result:
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
- analyzer = Marameters::Analyzer.new Demo.instance_method(:none).parameters
111
-
112
- analyzer.block # nil
113
- analyzer.block? # false
114
- analyzer.empty? # true
115
- analyzer.keywords # []
116
- analyzer.keywords? # false
117
- analyzer.kind?(:req) # true
118
- analyzer.kinds # []
119
- analyzer.name?(:three) # false
120
- analyzer.names # []
121
- analyzer.only_bare_splats? # false
122
- analyzer.only_double_splats? # false
123
- analyzer.only_single_splats? # false
124
- analyzer.positionals # []
125
- analyzer.positionals? # false
126
- analyzer.splats # []
127
- analyzer.splats? # false
128
- analyzer.to_a # []
129
- analyzer.to_h # {}
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 analyzer in that you want to feed it parameters for
135
- turning into a method signature. This is useful when dynamically building method signatures or using
136
- the same signature for multiple methods when metaprogramming.
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 is a hash _and_ some values can be tuples. The reason is that it's
159
- easier to write a hash than a double nested array as normally produced by the analyzer or directly
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 these as a normal string. There are two reasons why
189
- this is important:
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 that you want the object to be passed through without any further
192
- processing while also not being confused normal strings.
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. `#<Object:0x0000000107df4028>`)
195
- which is not what you want until much later when your method is defined.
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 #{signature}
206
- text
207
- end
205
+ def self.say(#{signature}) = text
208
206
  DEFINITION
209
207
  end
210
208
 
@@ -3,8 +3,8 @@
3
3
  require "refinements/arrays"
4
4
 
5
5
  module Marameters
6
- # Provides analysis of a method's parameters.
7
- class Analyzer
6
+ # Provides insight into a method's parameters.
7
+ class Probe
8
8
  using Refinements::Arrays
9
9
 
10
10
  # :reek:TooManyStatements
@@ -10,6 +10,8 @@ module Marameters
10
10
 
11
11
  def to_s = build.join ", "
12
12
 
13
+ alias to_str to_s
14
+
13
15
  private
14
16
 
15
17
  attr_reader :parameters, :builder
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.2.0"
5
+ spec.version = "0.3.2"
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.2.0
4
+ version: 0.3.2
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/jCCAeagAwIBAgIBBDANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
14
- a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMTAzMTkxMjQ4MDZaFw0yMjAzMTkx
15
- MjQ4MDZaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
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/gY4ggwDQYJKoZIhvcNAQELBQADggEBAEjpaOXHHp8s/7GL2qCb
24
- YAs7urOLv9VHSPfQWAwaTMVnSsIf3Sw4xzISOP/mmfEPBPXtz61K5esrE/uTFtgb
25
- FyjxQk2H0sEWgrRXGGNHBWQRhhEs7LP/TByoC15A0br++xLxRz4r7HBLGAWQQDpg
26
- 66BJ2TBVjxS6K64tKbq7+ACyrOZGgTfNHACh4M076y0x0oRf/rwBrU39/KRfuhbb
27
- cm+nNCEtO35gTmZ2bVDHLGvWazi3gJt6+huQjfXTCUUG2YYBxwhu+GPdAGQPxpf9
28
- lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
- W2A=
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-03-12 00:00:00.000000000 Z
31
+ date: 2022-04-23 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.9
103
+ rubygems_version: 3.3.12
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