forked from andypike/rectify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve Ruby 2.7 behavior for Ruby keyword args (#11)
Applies [`ruby2_keywords`](https://github.com/ruby/ruby2_keywords) to the `Command.call` method, which preserves the Ruby 2.7 behavior for keyword args. The result of these changes is that Rectify will continue to work with the existing behavior for keyword args once we've upgraded Panacea to Ruby 3. We've had to take this approach because fixing it would have also required us to upgrade Rectify to only work on Ruby `>= 3.0`. This is due to the fact that our particular use of kwargs in the Command pattern are considered a "corner case", preventing us from adopting the new behavior in our Ruby 2.7 code. See: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ - search this page for the string "If your code doesn’t have to run on Ruby 2.6 or older" ## So what does all this mean? In short, we don't have to worry about Rectify anymore. Once this has merged, we've released 0.14.0, and we've updated Panacea to use this new version, our existing use of Rectify Commands will continue to work even after we've upgraded the application to run on Ruby 3.0. This allows us to almost forget about the old Rectify-powered commands, and begin thinking about what tool or pattern we introduce to replace Rectify.
- Loading branch information
Showing
19 changed files
with
122 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ jobs: | |
with: | ||
bundler-cache: true | ||
- name: Run rubocop | ||
run: bin/rubocop | ||
run: bin/rubocop --format fuubar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
--color | ||
--format Fuubar | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
--display-style-guide | ||
--format fuubar | ||
--parallel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class ArgsCommand < Rectify::Command | ||
def initialize(a, b, c) # rubocop:disable Lint/MissingSuper, Naming/MethodParameterName | ||
@a = a | ||
@b = b | ||
@c = c | ||
end | ||
|
||
def call | ||
[a, b, c].join(" ") | ||
end | ||
|
||
private | ||
|
||
attr_reader :a, :b, :c | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class NamedArgsCommand < Rectify::Command | ||
def initialize(first_name, last_name, height:, location:, hobbies:) # rubocop:disable Lint/MissingSuper | ||
@first_name = first_name | ||
@last_name = last_name | ||
@height = height | ||
@location = location | ||
@hobbies = hobbies | ||
end | ||
|
||
def call | ||
broadcast(:ok, message) | ||
end | ||
|
||
def message | ||
"#{full_name} is from #{location} and is #{height_in_inches} inches tall, and they enjoy #{hobbies_list}." | ||
end | ||
|
||
private | ||
|
||
attr_reader :first_name, :last_name, :height, :location, :hobbies | ||
|
||
def full_name | ||
[first_name, last_name].join(" ") | ||
end | ||
|
||
def height_in_inches | ||
height * 0.393 | ||
end | ||
|
||
def hobbies_list | ||
hobbies_array = [hobbies].flatten | ||
|
||
if hobbies_array.length > 1 | ||
last_hobby = "and #{hobbies_array.pop}" | ||
hobbies_array.push(last_hobby) | ||
end | ||
|
||
hobbies_array.join(", ") | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters