Skip to content

Add bang version to OrderedOptions - #20208

Merged
rafaelfranca merged 1 commit into
rails:masterfrom
gaurish:raise_on_missing_ordered_options
May 26, 2015
Merged

Add bang version to OrderedOptions#20208
rafaelfranca merged 1 commit into
rails:masterfrom
gaurish:raise_on_missing_ordered_options

Conversation

@gaurish

@gaurish gaurish commented May 19, 2015

Copy link
Copy Markdown
Contributor

Every method should have a bang counter-part. if someone uses a bang version & its not defined. it will raise an ArgumentError.

example(normal version)
Rails.application.secrets.big_query

bang version
Rails.application.secrets.big_query!

By:
Aditya Sanghi(@asanghi)
Gaurish Sharma(@gaurish)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@gaurish Extra can be removed

@rafaelfranca

Copy link
Copy Markdown
Member

Thank you for the pull request.

Every method should have a bang counter-part.

Not true. There is no rule about this in any place and even if it is a rule, there is cases where it doesn't make sense.

I'm having problem to understand where this would be useful, could you give us an example?

@asanghi

asanghi commented May 20, 2015

Copy link
Copy Markdown
Contributor

@rafaelfranca Absolutely right, there is no such rule.

secrets.yml is more likely than not to contain passwords/keys to services which might be essential to your application's execution. Without those keys the application is unlikely to work as expected (or crash in unexpected ways). The bang version of the method basically allows us to crash in a more expected way, letting us know that a blank has been encountered when it's not expected. In absence of this, we're more likely to write custom code checking for blanks and handling it with custom error methods (and then possibly erroring out anyway).

Case in point

if (slack_url = Rails.application.secrets.slack_url).present?
  $slack_notifier = Slack::Notifier.new(slack_url)
else
  Rails.logger.error("Unable to find slack_url in secrets.yml")
  raise "Unable to find slack_url in secrets.yml"
end

gets replaced by

  $slack_notifier = Slack::Notifier.new(Rails.application.secrets.slack_url!)

This is a similar style to .save!, and .create! methods where ! indicates that an exception might be raised by this method call.

What do you think?

@rafaelfranca

Copy link
Copy Markdown
Member

@asanghi thanks for the explanation.

@gaurish Could you add a CHANGELOG entry?

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.

Can we use if/else? The line is too long.

@gaurish

gaurish commented May 23, 2015

Copy link
Copy Markdown
Contributor Author

PR Updated according to feedback given.

By:
Aditya Sanghi(@asanghi)
Gaurish Sharma(gaurish)
@asanghi

asanghi commented May 26, 2015

Copy link
Copy Markdown
Contributor

/cc @rafaelfranca seems okay now?

@rafaelfranca
rafaelfranca merged commit e768c51 into rails:master May 26, 2015
rafaelfranca added a commit that referenced this pull request May 26, 2015

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small nitpick: The last closing parens should be deleted.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants