Skip to content

Instantly share code, notes, and snippets.

@volodymyr-nt
Created October 10, 2016 09:17
Show Gist options
  • Select an option

  • Save volodymyr-nt/aa241534f9a1c25ef4fa0a01882fc4e4 to your computer and use it in GitHub Desktop.

Select an option

Save volodymyr-nt/aa241534f9a1c25ef4fa0a01882fc4e4 to your computer and use it in GitHub Desktop.
# base implementation of service object pattern
class Service
def self.call(*params)
new(*params).call
end
class ServiceResponse
def error?
!success?
end
end
class SuccessResponse < ServiceResponse
attr_reader :data
def initialize(data)
@data = data
end
def success?
true
end
end
class ErrorResponse < ServiceResponse
attr_reader :errors
def initialize(errors = [])
@errors = error_messages
end
def push(error)
@errors.push(error)
end
def success?
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment