-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix module/class nesting in calculator/* #2312
Fix module/class nesting in calculator/* #2312
Conversation
max = preferred_max_items.to_i | ||
quantity.times do |i| | ||
# check max value to avoid divide by 0 errors | ||
if (max == 0 && i == 0) || (max > 0) && (i % max == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use max.zero? instead of max == 0.
Use i.zero? instead of i == 0.
Use (i % max).zero? instead of i % max == 0.
|
||
return BigDecimal.new(0) if items_count == 0 | ||
return BigDecimal.new(0) if items_count == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use items_count.zero? instead of items_count == 0.
2e244fa
to
dfbf5d5
Compare
@@ -1,58 +1,60 @@ | |||
require_dependency 'spree/calculator' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this require make the change unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not require_dependency'd everywhere its defined/used.
I'd say we fix the definitions to be consistent and not have to worry about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also prefer require_dependency
over re-defining the same classes several times (and with that potential errors in future changes)
Okay, I don't personally agree with the require_dependency over keeping the class definitions the same, but I'll switch it. Are we okay with me leaving them broken out so its clear Calculator is a class and not a module? |
Since our class declarations are so busted, we need to ensure this is lodaed first.
dfbf5d5
to
8215101
Compare
Spree::Calculator is a class (that inherits from Spree::Base), but in
these definitions we don't clarify it as such.