Skip to content
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

Fewer ActiveSupport core extensions #318

Merged
merged 3 commits into from Mar 16, 2020
Merged

Fewer ActiveSupport core extensions #318

merged 3 commits into from Mar 16, 2020

Conversation

@orien
Copy link
Member

orien commented Mar 16, 2020

Require fewer ActiveSupport core extensions.

require 'active_support/core_ext/string'
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/string/inflections'

This comment has been minimized.

Copy link
@orien

orien Mar 16, 2020

Author Member

Previously, when requiring active_support/core_ext/string it'd load all these string extensions:

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string.rb

Which would in turn load a bunch of other core extensions.

Let's be a little more explicit about the extensions StackMaster uses, and only load these.

@@ -12,7 +12,7 @@ def resolve(value)
owners = Array(value.fetch('owners', 'self').to_s)
ami_finder = AmiFinder.new(@stack_definition.region)
filters = ami_finder.build_filters_from_hash(value.fetch('filters'))
ami_finder.find_latest_ami(filters, owners).try(:image_id)
ami_finder.find_latest_ami(filters, owners)&.image_id

This comment has been minimized.

Copy link
@orien

orien Mar 16, 2020

Author Member

Now that we require Ruby >= 2.4, we can use the Ruby safe navigation operator, instead of ActiveSupport's try.

@@ -71,7 +71,7 @@ def format
newlines = lines.split("\n").map do |line|
"#{line}#{newlines.pop}"
end
if lines.starts_with?("\n")
if lines.start_with?("\n")

This comment has been minimized.

Copy link
@orien

orien Mar 16, 2020

Author Member

Active support aliases Ruby's start_with? to starts_with?.

Let's just use the method that comes with Ruby.

@@ -1,6 +1,5 @@
#!/usr/bin/env ruby

require 'rubygems'

This comment has been minimized.

Copy link
@orien

orien Mar 16, 2020

Author Member

This is not needed.

Copy link
Contributor

patrobinson left a comment

💯

@orien orien merged commit d598e12 into master Mar 16, 2020
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@orien orien deleted the require-core-ext branch Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.