-
Notifications
You must be signed in to change notification settings - Fork 341
Allow arbitrary setup code to be inserted into binstub #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -69,6 +69,12 @@ def binstub_name | |||
"bin/#{name}" | |||
end | |||
|
|||
def binstub_code | |||
if command.respond_to?(:binstub_code) | |||
command.binstub_code.gsub(/[^\n]\z/) { |eos| "#{eos}\n" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about command.binstub_code + "\n"
? - no worries about an extra newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, better to handle this when the binstub is written anyway. Introduce a \n
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremy - How's this? |
@merhard - Cool. Considering this is a shim that needs to run only when the executable is sprung, consider giving begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
# command's post-spring shim doesn't load if spring isn't in use
else
<command's post-spring shim>
end |
@jeremy - I renamed |
@merhard Nice. |
@jeremy How's this? I can squash the commits if there isn't anything else. |
@@ -104,8 +104,14 @@ def generate(fallback = nil) | |||
fallback = "require 'bundler/setup'\n" \ | |||
"load Gem.bin_path('#{command.gem_name}', '#{command.exec_name}')\n" | |||
end | |||
if prelude = command.binstub_prelude | |||
formatted_prelude = prelude.chomp.gsub(/^(?!$)/, ' ') | |||
loader = LOADER.sub(/^end$/, "else\n#{formatted_prelude}\n\\0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the story with the trailing NUL
byte?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh cool! Double backslash. That's cool - but yeah, end
would be clearer 😁
@jeremy changed |
@merhard Super! Squash? |
@jeremy squashed |
Allow arbitrary setup code to be inserted into binstub
👍 |
thanks |
Was this change specifically aimed at fixing the rspec issue or was some more general use case envisaged? |
It is designed to be used by any |
Sure, I realise that it can be used by any command, however I'm dubious about whether we actually need this feature, hence I wanted to see if there were other reasons to add it. (For others: I suggested an alternative fix to the rspec issue at jonleighton/spring-commands-rspec#20 (comment)) |
This reverts commit 2480a8e, reversing changes made to 9cd21d2. Revert "Changelog: binstub_prelude support for commands. #329." This reverts commit 8a3546d. Conflicts: CHANGELOG.md Reasoning: * #329 (comment) * jonleighton/spring-commands-rspec#20 (comment) * 2480a8e Since the thing that this feature was aiming to allow is already possible via the commands API, I prefer not to add an extra feature to Spring.
This reverts commit 2480a8eb4e88ad720e3d5a30bc23b53201673d58, reversing changes made to 9cd21d2249fdc33477dfc99f0e99c5d307108447. Revert "Changelog: binstub_prelude support for commands. #329." This reverts commit 8a3546d15892f28f19787d88e4a834e68b91c438. Conflicts: CHANGELOG.md Reasoning: * rails/spring#329 (comment) * jonleighton/spring-commands-rspec#20 (comment) * rails/spring@2480a8e Since the thing that this feature was aiming to allow is already possible via the commands API, I prefer not to add an extra feature to Spring.
This commit is designed to be the first step to solving this issue.
The pull request would allow the spring-commands-rspec gem to be changed to:
The generated rspec binstub would then be: