-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add CONTRIBUTING.md #3209
Add CONTRIBUTING.md #3209
Conversation
This is meant to be a set of guidelines for anyone contributing to follow, and this PR is meant to spark constructive ctriticism. Please feel free to propose additions where any might be lacking, and modifications with good justification.
- follow Sandi Metz' [rules][sm] | ||
- prefer [composition over inheritance][composition] | ||
|
||
[composition]: https://betterprogramming.pub/prefer-composition-over-inheritance-1602d5149ea1 |
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.
IMO the article is dogmatic, other's like such as https://thoughtbot.com/blog/reusable-oo-composition-vs-inheritance suggest that the developer should understand the trade-off between composition vs inheritance.
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 agree, that's why I put prefer.
Another thought I had was mimicking the behavior of mutations and interactor, but which a much simpler setup, something like: # frozen_string_literal: true
module My
class Service < BaseService
class COMMAND
include ActiveModel::Validations
validates_presence_of :param1
validates_presence_of :param2
end
def self.build
new(tp_need: TPNeed)
end
def initialize(tp_need:)
@tp_need = tp_need
end
def execute(param1:, param2)
result = @tp_need.do_something(param1, param2)
if not result
return fail("Some error message")
end
success("Did thing")
end
end
end
end The base class would be something like 40 lines of ruby and would give us what we need with no extra frameworks. It instantiates the COMMAND class with the parameters and validates, if validation passes, it calls execute. For most things you could probably even leave out the COMMAND -- since the type system could take care of basic things like non-nil, etc.. could add it in for more complex scenarios like email validation. But we can leave this for a followup-PR. |
@yachtcaptain23 going to merge this tomorrow unless any further thoughts. |
This is meant to be a set of guidelines for anyone contributing to follow, and this PR is meant to spark constructive criticism.
Please feel free to propose additions where any might be lacking, and modifications with good justification.