-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Initial batch of swapping Active Support extensions for in-house alternatives (WIP) #881
Conversation
…rnatives - new `within?` method offers some unique semantics
Your Render PR Server URL is https://bridgetown-beta-pr-881.onrender.com. Follow its progress at https://dashboard.render.com/static/srv-cod3jmv79t8c739bpeo0. |
Your Render PR Server URL is https://bridgetown-api-pr-881.onrender.com. Follow its progress at https://dashboard.render.com/static/srv-cod3jn779t8c739bpeu0. |
Is it worth separating our extensions from |
@ayushn21 Ooo, I love that idea! I can immediately think of a few other existing core utilities we could extract out as well. Could then be a nice little standalone gem. Any ideas on what to call it? |
It's not the most creative name, but maybe |
@ayushn21 Ah, hmm well that would keep the scope pretty small (and not appropriate for the utilities I was thinking about). Let me chew on that… |
- Remove unneeded Active Support extensions once thought to be necessary for Thor actions
@ayushn21 what do you think about |
|
|
(An abutment is the part of a bridge that provides the support necessary to distribute the weight and stresses from the bridge to the ground, and typically anchors the bridge at either end.) |
@brandondrew I like the direction you're headed in…too bad that word immediately gets me thinking about juvenile humor… 😏😂 |
yeah, I should have thought of that... |
What about Bridgetown Bridge? I think the repetition sounds great, but also the concept and the meta reference are interesting. |
|
@brandondrew Or could go with |
I'm quite partial to But it's also a nice parallel to the iOS/Mac platform. There you have the base language (Swift or Obj-C) and then a framework called "Foundation" which sits on top of that containing a bunch of Apple system APIs. On top of that you have the framework for the platform you're developing on (UIKit, AppKit, whatever else...). |
@ayushn21 Let's go with that then. Sounds good to me! |
- translation safety - module nesting - also clean up outdated subclass tracking for route class files
…atching - new .() and .with() features for Symbol
Bit of a direction switch with the latest commit…I have been an unabashed fan of Ruby refinements for the longest time, but a while back I was sort of talked out of the idea due to the performance hit of using a refined method. Well I'm coming back around to the idea of it being a good thing. I did some benchmarking on a String using a refined method vs a standard monkey-patched method, and standard monkey-patching was about 1.25x the performance. So the question starts to become, how often does this a refined method get called during a span of time (a build process or an HTTP request, essentially)? 1 time? 5 times? 100 times? Unless it's being called literally thousands of times (I only started to see major "real time" difference in the millions), I think we're splitting hairs. We can identify certain code paths where cumulative performance is absolutely critical (so I might back out of a few changes in that recent commit), but otherwise I think it's worth it. "indent me!".indent(2) # NoMethodError
using Bridgetown::Refinements
"indent me!".indent(2) # " indent me!" is just so cool. Of course you could also just reach for individual refinements, which is as close to "imports" as you'll get in Ruby: "indent me!".indent(2) # NoMethodError
using Bridgetown::Foundation::RefineExts::String
"indent me!".indent(2) # " indent me!" I'm still sussing out what we might want as core extensions globally vs. refinements. Thoughts? Questions? Ideas? |
OK, this PR is fairly well baked at this point…I'll leave it open for a while for anything else which feels like low-hanging fruit, but generally it seems in good shape to pull into the v2.0 release. |
I checked this out to see if it broke anything. Trying to run a build for us results in the following error. I looked through this PR, but wasn't able to hunt down what cause this. I'm not sure if this is something with [Bridgetown] Stopping auxiliary processes...
[Bridgetown] Exception raised: NameError
[Bridgetown] uninitialized constant ActionView::OutputBuffer
[Bridgetown] 1: /Users/jarrett/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionview-7.1.3.2/lib/action_view/helpers/capture_helper.rb:49:in `capture'
[Bridgetown] 2: /Users/jarrett/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bundler/gems/bridgetown-e172990a669c/bridgetown-core/lib/bridgetown-core/component.rb:167:in `render' |
@jclusso Hmm…well Action View was never something we pulled into core, but that gets me wondering if you are also using ViewComponent? |
We're just using class SiteComponent < Bridgetown::Component
include ActionView::Helpers::TagHelper
end |
If I follow the stack trace above it leads me to:
which inherits from
I'm not sure how any of this works really. |
Were you ever able to hunt anything down related to why this breaks? |
@jclusso I don't have a clear idea, but I'm wondering if you'd need to add a require for |
Going to add a separate issue for some documentation on this, but otherwise…LGTM! |
I can confirm this fixes it. Not sure where this should go, but documentation should be added for people upgrading to know if they rely on Active Support that they need to add them gem and require it. I currently have required |
@jclusso OK fabulous. I'll make a note to include this in an upgrade guide. |
|
Congruent with our stated goals for Bridgetown 2.0 here: https://www.bridgetownrb.com/future/road-to-bridgetown-2.0-escaping-burnout/
This PR offers an initial batch of in-house Ruby extensions in lieu of using Active Support dependencies. It also sets up a paradigm of using Zeitwerk and modules to manage core object inclusions. Update: see below for thoughts about mostly relying on refinements vs. standard monkey-patches.
.questionable
lets us continue using the nicety ofBridgetown.env.development?
.starts_with?
andends_with?
as alias ofstart_with?
andend_with?
.within?
as a souped-up version ofin?
— companions of Module/Classes, Sets, and Hashes are nicer because they use the<
operator. Makes sense that{easy_as: 123}
would be.within?({indeed: "it's true", easy_as: 123})
. Arrays/Arrays use.difference
under the hood, so that[1,2]
would be within[5,4,3,2,1]
.nested_within?
lets you see ifFoo::Bar
is nested withinFoo
, and you can also access nested parent modules/classes with.nested_parents
deep_dup
for Hashes/Arraysmethod_missing
calls.Note that not all extensions will necessarily make the cut as we go through this process, but these all feel like worthwhile endeavors to me.
Feedback welcome!