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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ The format is based on [Keep a Changelog], and this project adheres to

### Changed

- Load fewer Ruby files: remove several ActiveSupport core extensions and
Rubygems `require`s ([#318]).

### Fixed

- `stack_master apply` prints list of parameter file locations if no stack
Expand All @@ -23,6 +26,7 @@ The format is based on [Keep a Changelog], and this project adheres to
[Unreleased]: https://github.com/envato/stack_master/compare/v2.2.0...HEAD
[#316]: https://github.com/envato/stack_master/pull/316
[#317]: https://github.com/envato/stack_master/pull/317
[#318]: https://github.com/envato/stack_master/pull/318

## [2.2.0]

Expand Down Expand Up @@ -53,6 +57,7 @@ The format is based on [Keep a Changelog], and this project adheres to
[2.2.0]: https://github.com/envato/stack_master/compare/v2.1.0...v2.2.0
[#248]: https://github.com/envato/stack_master/issues/248
[#310]: https://github.com/envato/stack_master/pull/310
[#312]: https://github.com/envato/stack_master/pull/312
[#313]: https://github.com/envato/stack_master/pull/313
[#314]: https://github.com/envato/stack_master/pull/314
[#315]: https://github.com/envato/stack_master/pull/315
Expand Down
1 change: 0 additions & 1 deletion bin/stack_master
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env ruby

require 'rubygems'
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not needed.

require 'stack_master'

if ENV['STUB_AWS'] == 'true'
Expand Down
4 changes: 3 additions & 1 deletion lib/stack_master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
require 'aws-sdk-sns'
require 'aws-sdk-ssm'
require 'colorize'
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'
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

require 'multi_json'

MultiJson.use :json_gem
Expand Down
2 changes: 1 addition & 1 deletion lib/stack_master/parameter_resolvers/latest_ami.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

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

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

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(config, stack_definition)

def resolve(value)
filters = @ami_finder.build_filters_from_string(value, prefix = "tag")
@ami_finder.find_latest_ami(filters).try(:image_id)
@ami_finder.find_latest_ami(filters)&.image_id
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stack_master/sparkle_formation/template_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member Author

@orien orien Mar 16, 2020

Choose a reason for hiding this comment

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

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

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

newlines.insert(0, "\n")
end
newlines
Expand Down