Skip to content
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

Create abstract action parent class #568

Conversation

andrewdicken-stripe
Copy link
Contributor

@andrewdicken-stripe andrewdicken-stripe commented Nov 1, 2022

Most actions within the actions folder function very similarly and can be implemented by a shared parent class to reduce the repeated code. This also allows people to more easily monkey patch the functionality of all NetSuite actions in one call rather than needing to edit the functionality of every single NetSuite action.

@andrewdicken-stripe
Copy link
Contributor Author

Question for code reviewer: lib/netsuite/actions/login.rb is within the actions folder but does not follow the normal pattern of having an inner Support module and seems to be structured fairly different than the other actions. Is it worth implementing the abstract action pattern for that file or should we just leave that one out of this change?

Comment on lines -25 to -28
def request
raise NotImplementedError, 'Please implement a #request method'
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be deleted or else the code will never find abstract_action's request method

@andrewdicken-stripe andrewdicken-stripe changed the title [WIP] Create abstract action Create abstract action parent class Mar 24, 2023
@@ -1,7 +1,9 @@
# https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/add.html
require_relative 'abstract_action'
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need these, I'm pretty sure we can autoload them in lib/netsuite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh I didn't see that I could do that. Much cleaner.

raise NotImplementedError, 'Not implemented on abstract class'
end

def request_options
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason we wouldn't default to {} and omit these dup methods on the specific actions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I did this for the request_options method. request_body has a different implementation for each subclass so I left that one as is.

module NetSuite
module Actions
class AbstractAction
def request(credentials={})
Copy link
Member

Choose a reason for hiding this comment

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

can you link to this PR in a comment to help explain why this pattern is being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a link to this PR to my WIP PR where I'm implementing the monkey patch for AbstractAction. Is that what you were referring to? https://git.corp.stripe.com/stripe-internal/pay-server/pull/596685/files#r2504037

@iloveitaly iloveitaly merged commit 8c7f7b4 into NetSweet:master Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants