-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
@tdantas did you look at this? |
lib/usecasing/base.rb
Outdated
end | ||
|
||
def perform(ctx = { }) | ||
tx(ExecutionOrder.run(self), ctx) do |usecase, context| | ||
instance = usecase.new(context) | ||
instance.tap do | me | | ||
me.required_params | ||
puts self |
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.
Please remove the debug statement
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.
Done
lib/usecasing/base.rb
Outdated
end | ||
|
||
def perform(ctx = { }) | ||
tx(ExecutionOrder.run(self), ctx) do |usecase, context| | ||
instance = usecase.new(context) | ||
instance.tap do | me | | ||
me.required_params |
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.
This should denote an action, probably a better name would be extract_required_params
.
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.
Also, i would avoid using require
(and any variation) since you don't enforce it, we are just copying the variables from the context to the usecase instance.
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.
Now the method raises an exception when a given parameter does not exist in the context so i think required_params
is a good name now.
lib/usecasing/base.rb
Outdated
@@ -31,6 +40,13 @@ def perform(ctx = { }) | |||
|
|||
private | |||
|
|||
def concat_superclass_variable(variable) |
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.
This method does not do any actual concatenation. Please find a better name to describe the action.
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 made some changes and I deleted this method.
|
||
it 'includes params from the superclasses' do | ||
AppUseCase = Class.new(UseCase::Base) do | ||
required_params :param |
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.
Please rename required_params
in order to denote an action.
spec/usecase_base_spec.rb
Outdated
@@ -66,6 +92,19 @@ def perform | |||
expect(ctx.email).to eql('thiago.teixeira.dantas@gmail.com') | |||
end | |||
|
|||
it 'receives a hash and return it' do | |||
|
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.
Remove empty line.
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.
Done
spec/usecase_base_spec.rb
Outdated
UseCaseSubClass = Class.new(AppUseCase) | ||
|
||
expect(UseCaseSubClass.required_params).to eql([:param]) | ||
|
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.
Remove empty line
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.
Done
spec/usecase_base_spec.rb
Outdated
@@ -40,6 +40,32 @@ | |||
|
|||
end | |||
|
|||
context "required_params" do | |||
|
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.
Remove empty line
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.
Done
spec/usecase_base_spec.rb
Outdated
@@ -85,7 +124,7 @@ def perform | |||
pending | |||
end | |||
|
|||
it 'fail when usecase register failure' do | |||
it 'fail when usecase register failure' do |
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.
Remove extra space
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.
Done. Thanks.
…es not exist in the context.
76211d1
to
7a30c74
Compare
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.
👍
c9ff87a
to
7f2df9d
Compare
@tdantas any opinion about this? |
Description
Add a "required_params" method to use it like this:
and when the perform method is called, "context_params" will create instances variables for this params.
Issue
A disscusion about this issue: #9