Created
November 5, 2024 17:55
-
-
Save Hasstrup/0605b19a34473b3f35111ffaae41ab65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# BaseService serves as a foundational class for creating service objects | |
# in the application. It provides a standardized interface for service calls | |
# and integrates error handling mechanisms. | |
class BaseService | |
class ServiceError < StandardError; end | |
class InvalidInputError < StandardError; end | |
include ErrorHandling::Validatable | |
# Calls the service with the provided keyword arguments. | |
# | |
# @param [Hash] kwargs The keyword arguments to be passed to the service. | |
# @return [Object] The result of the service call. | |
def self.call(**kwargs) | |
new(**kwargs).call | |
end | |
# Executes the service logic. Must be implemented in subclasses. | |
# | |
# @raise [NotImplementedError] When not implemented in a subclass. | |
def call | |
raise NotImplementedError | |
end | |
delegate :fail!, :succeed, to: :context | |
private | |
attr_reader :input | |
# Initializes the context for the service. | |
# | |
# @return [Context] The service context. | |
def context | |
@context ||= Context.new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment