marameters 4.0.1 → 4.1.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 +0 -1
- data/lib/marameters/signatures/defaulter.rb +1 -1
- data/lib/marameters/sourcers/function.rb +28 -0
- data/lib/marameters/sourcers/readers/any.rb +29 -0
- data/lib/marameters/sourcers/readers/disk.rb +18 -0
- data/lib/marameters/sourcers/readers/memory.rb +10 -0
- data/lib/marameters/sources/extractor.rb +3 -0
- data/lib/marameters/sources/reader.rb +3 -0
- data/marameters.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +6 -2
- metadata.gz.sig +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e75fcf0d2ce27a87be66111142b52633ccd85f157a8590f85e0bc22f3d45383
|
4
|
+
data.tar.gz: 8195f5f72414fe01cb28acc32df595f380bc072f5dac47a905a87646c4086b89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a9ebbb23019fe2a76e62737b3bef254bd2ca62908d45fe047492f1615a72ec74c110b272bd3081d8984f2fea581535b83cdf4590b41b61492a64664b3bc3a9
|
7
|
+
data.tar.gz: 2e440c9a5d431da24abd551ae7ffc5f712bacf53203e2de82d0d25806b762dcc031f5fb4425809081fa635f287fccadc279e3c2a4c3a6cd8cdb3452d0ff4a267
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -449,7 +449,6 @@ puts Marameters.signature([[:key, :demo, :test]])
|
|
449
449
|
# With proc (no parameters).
|
450
450
|
puts Marameters.signature([[:key, :demo, proc { Object.new }]])
|
451
451
|
# "demo: Object.new"
|
452
|
-
# ⚠️ The above will answer "demo: nil" if used in IRB since the source can't be found.
|
453
452
|
|
454
453
|
# With proc (with parameters).
|
455
454
|
puts Marameters.signature([[:key, :demo, proc { |no| no }]])
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Marameters
|
4
4
|
module Signatures
|
5
5
|
# Computes a method parameter's default value.
|
6
|
-
Defaulter = lambda do |value, extractor:
|
6
|
+
Defaulter = lambda do |value, extractor: Sourcers::Function.new|
|
7
7
|
case value
|
8
8
|
when Proc
|
9
9
|
fail TypeError, "Use procs instead of lambdas for defaults." if value.lambda?
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Marameters
|
4
|
+
module Sourcers
|
5
|
+
# Obtains the literal source of a function's body.
|
6
|
+
class Function
|
7
|
+
PATTERN = /
|
8
|
+
(?:(?<function>proc|->))? # Statement.
|
9
|
+
\s* # Optional space.
|
10
|
+
\{ # Block open.
|
11
|
+
(?<body>.*?) # Source code body.
|
12
|
+
\} # Block close.
|
13
|
+
/x
|
14
|
+
|
15
|
+
def initialize pattern: PATTERN, reader: Readers::Any.new
|
16
|
+
@pattern = pattern
|
17
|
+
@reader = reader
|
18
|
+
freeze
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(function) = reader.call(function).then { |line| line.match(pattern)[:body].strip }
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :pattern, :reader
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Marameters
|
4
|
+
module Sourcers
|
5
|
+
module Readers
|
6
|
+
# Reads source code of callable from disk or memory.
|
7
|
+
class Any
|
8
|
+
def initialize parser: RubyVM::InstructionSequence, disk: Disk, memory: Memory
|
9
|
+
@parser = parser
|
10
|
+
@disk = disk
|
11
|
+
@memory = memory
|
12
|
+
freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
def call callable
|
16
|
+
instructions = parser.of callable
|
17
|
+
|
18
|
+
fail StandardError, "Unable to load source for: #{callable.inspect}." unless instructions
|
19
|
+
|
20
|
+
instructions.absolute_path ? disk.call(instructions) : memory.call(instructions)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :parser, :disk, :memory
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Marameters
|
4
|
+
module Sourcers
|
5
|
+
module Readers
|
6
|
+
# Reads source code from on-disk instruction sequence.
|
7
|
+
Disk = lambda do |instructions|
|
8
|
+
path = instructions.absolute_path
|
9
|
+
line_start, column_start, line_end, column_end = instructions.to_a.dig 4, :code_location
|
10
|
+
lines = File.read(path).lines[(line_start - 1)..(line_end - 1)]
|
11
|
+
lines[-1] = lines.last.byteslice(...column_end)
|
12
|
+
lines[0] = lines.first.byteslice(column_start..)
|
13
|
+
|
14
|
+
lines.join
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -5,6 +5,9 @@ module Marameters
|
|
5
5
|
# Reads object source code from memory or file (assumes implementation is a one-liner).
|
6
6
|
class Reader
|
7
7
|
def initialize offset: 1, parser: RubyVM::InstructionSequence, io: File
|
8
|
+
warn "`#{self.class}` is deprecated, use `Sourcers::Readers::Any` instead.",
|
9
|
+
category: :deprecated
|
10
|
+
|
8
11
|
@offset = offset
|
9
12
|
@parser = parser
|
10
13
|
@io = io
|
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: 4.0
|
4
|
+
version: 4.1.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:
|
37
|
+
date: 2025-01-10 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: refinements
|
@@ -84,6 +84,10 @@ files:
|
|
84
84
|
- lib/marameters/signatures/forwarder.rb
|
85
85
|
- lib/marameters/signatures/inheritor.rb
|
86
86
|
- lib/marameters/signatures/super.rb
|
87
|
+
- lib/marameters/sourcers/function.rb
|
88
|
+
- lib/marameters/sourcers/readers/any.rb
|
89
|
+
- lib/marameters/sourcers/readers/disk.rb
|
90
|
+
- lib/marameters/sourcers/readers/memory.rb
|
87
91
|
- lib/marameters/sources/extractor.rb
|
88
92
|
- lib/marameters/sources/reader.rb
|
89
93
|
- marameters.gemspec
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
�
|
2
|
-
�
|
1
|
+
>$�&u���Zv����"'���Cv-Y��2����k��J��2�3/���ֿH�$�>��L��P���T��)��A�Hqma$JR�DS4��B�m�N9��j�:��T�N��Aq)b�T���uO��7so+� b�����L�tE��
|
2
|
+
|��w�e�^��O�Y���o>eTa���#-6im���5ÁK�|�X%�u�eV)C>�%YH,k%3�g@ m�;��>G�+�>�+@��y*W�
|
3
|
+
[�q�t�ZCߚ�k�չ&�b��ʂ��V���',�������v�y��"�8����-��I��#��P
|