Skip to content

Add export(typed: false) to ParamProxy and rewrite_signature to MethodProxy - #9

Open
obsidiannnn wants to merge 6 commits into
low-rb:mainfrom
obsidiannnn:feature/export-api
Open

Add export(typed: false) to ParamProxy and rewrite_signature to MethodProxy#9
obsidiannnn wants to merge 6 commits into
low-rb:mainfrom
obsidiannnn:feature/export-api

Conversation

@obsidiannnn

Copy link
Copy Markdown
Contributor

Summary

Adds two new methods to Lowkey as foundational pieces for the
LowType method rewriting project (low-rb/low_type#38).

Changes

ParamProxy#export(typed: false)

  • typed: true (default) - existing behavior, returns raw source
  • typed: false - returns plain param string without type annotation,
    using param name and expression.default_value

MethodProxy#rewrite_signature

  • Rebuilds the method signature line using export(typed: false)
    on each param proxy
  • Splices the result back into the shared lines array in-place
  • Since all proxies share the same lines reference,
    file_proxy.export reflects the change automatically

Tests

29 examples, 0 failures - all existing specs pass plus
10 new specs covering both methods.

Comment thread lib/proxies/method_proxy.rb Outdated
Comment thread lib/proxies/method_proxy.rb Outdated
all_params = @params.map do |p|
p.expression ? p.export(typed: false) : p.name.to_s
end
rebuilt = "#{indent}#{scope_prefix}#{@name}(#{all_params.join(', ')})"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a method like lines that handles the indentation logic for us. lines will work if we jus pass in an array of one line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will look at using lines to handle the indentation instead of building it manually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use lines=(new_lines) instead of lines[start_index] = ... then it should handle the indent for you? It's doing very similar logic to the indent = original[/^\s*/] bit: https://github.com/low-rb/lowkey/blob/main/lib/models/source.rb#L19

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you can keep original = lines[start_index] for the original.match?(/def self\./) ? 'def self.' : 'def ' bit but no need for indent = original[/^\s*/] here I believe

Comment thread lib/proxies/param_proxy.rb
Comment thread lib/proxies/param_proxy.rb Outdated
Comment thread lib/proxies/method_proxy.rb Outdated
Comment thread lib/models/source.rb Outdated
Comment thread lib/proxies/method_proxy.rb Outdated
Comment thread lib/proxies/method_proxy.rb Outdated
indent = original[/^\s*/]
lines[start_index] = indent + sig_lines[0].lstrip
return_suffix = @return_proxy ? " #{@return_proxy.export}" : ''
self.lines = ["#{scope_prefix}#{@name}(#{all_params.join(', ')})#{return_suffix}\n"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the lines=(new_lines) method I believe, cool

@obsidiannnn
obsidiannnn force-pushed the feature/export-api branch from d5279d3 to 48c5041 Compare July 7, 2026 14:42
Comment thread lib/models/source.rb Outdated

def rewrite_signature
old_line = lines[start_index]
scope_prefix = old_line.match?(/def self\./) ? 'def self.' : 'def '

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a blocker but I wonder if a method proxy already has info on whether it's a class method or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants