Skip to content

Instantly share code, notes, and snippets.

@krzykamil
Last active August 20, 2020 12:41
Show Gist options
  • Save krzykamil/e3dc6520a3953ed38998e91c19a34f07 to your computer and use it in GitHub Desktop.
Save krzykamil/e3dc6520a3953ed38998e91c19a34f07 to your computer and use it in GitHub Desktop.
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