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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1499010bf03407332bde415ad66e861d6ba68dbcd71c2612b8bb205ca9002e86
4
- data.tar.gz: 0a019c4746630f7b5160468a69e1b1b944273ec6a5938d1a63816f25f3cdff7c
3
+ metadata.gz: 4e75fcf0d2ce27a87be66111142b52633ccd85f157a8590f85e0bc22f3d45383
4
+ data.tar.gz: 8195f5f72414fe01cb28acc32df595f380bc072f5dac47a905a87646c4086b89
5
5
  SHA512:
6
- metadata.gz: be3f541897eabc80c899fe2f1a4c2e7d0c9ea78b6c75df0443d9f24c6123b684f0dacbe61061a86f0c5796eefb251b2fde9f69bd9fc533a973f82b40360e4460
7
- data.tar.gz: a725045f723817c8c124699e1902063e689c09dcf8dbe44d46c48fd27191cf6b0f80379f8b8d4d5383d5cccf40a13cd4d41d52c33efc418f65358c947d4081cc
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: Sources::Extractor.new|
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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Marameters
4
+ module Sourcers
5
+ module Readers
6
+ # Reads source code from in-memory instruction sequence.
7
+ Memory = -> instructions { instructions.script_lines.join.chomp }
8
+ end
9
+ end
10
+ end
@@ -13,6 +13,9 @@ module Marameters
13
13
  /x
14
14
 
15
15
  def initialize pattern: PATTERN, reader: Reader.new
16
+ warn "`#{self.class}` is deprecated, use `Sourcers::Function` instead.",
17
+ category: :deprecated
18
+
16
19
  @pattern = pattern
17
20
  @reader = reader
18
21
  @fallback = "nil"
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "marameters"
5
- spec.version = "4.0.1"
5
+ spec.version = "4.1.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://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: 4.0.1
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: 2024-12-28 00:00:00.000000000 Z
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
- V�7>dP)����u��%�� ye�ٺ�%*��B#4rn
2
- [>��%"NXz����L4B��-A|
1
+ >$ �&u ���Zv����"'���Cv-Y��2����k��J��23 /���ֿH�$ �>��L��P���T�‹�)��޼A�Hqma$JR�DS4��B�mN9��j�:��T�N��Aq)b�T���uO��7so+� b�����L�tE��
2
+ |��we�^��OY���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