Last active
August 20, 2020 12:41
-
-
Save krzykamil/e3dc6520a3953ed38998e91c19a34f07 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
class BaseService | |
attr_reader :result, :errors | |
def self.call(**args) | |
new(**args).tap(&:call) | |
end | |
def success? | |
errors.blank? | |
end | |
end | |
module Users | |
class Create < BaseService | |
def initialize(**facebook_profile) | |
@facebook_profile = facebook_profile | |
super() | |
end | |
def call | |
user = User.new( | |
jti: SecureRandom.uuid, | |
**facebook_profile, | |
) | |
if user.save | |
@result = user | |
else | |
@errors = { field: nil, key: 'user.create.failed' } | |
end | |
end | |
private | |
attr_reader :facebook_profile | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment