Skip to content

Instantly share code, notes, and snippets.

@fathur
Last active April 15, 2019 10:15
Show Gist options
  • Select an option

  • Save fathur/9e74129fc8c3f24ac6390443d48d999b to your computer and use it in GitHub Desktop.

Select an option

Save fathur/9e74129fc8c3f24ac6390443d48d999b to your computer and use it in GitHub Desktop.
class MidwifeRegistrationService
def initialize(options = {})
@params = options[:params]
end
def call
create_user
send_sms
self
end
def call!
validate
call
end
def validate
end
def create_user
@data = Midwife.create()
@data.create_prop()
end
def send_sms
SmsOtpBackground.enqueue @data.id
end
end
class MotherRegistrationService
def initialize(options = {})
@params = options[:params]
end
def call
create_user
send_email
self
end
def call!
validate
call
end
def validate
end
def create_user
@data = Mother.create()
@data.create_prop()
end
def send_email
EmailOtpBackground.enqueue @data.id
end
end
class RegistrationService
def initialize(options = {})
@headers = options[:headers]
@params = options[:params]
end
def call
role = @headers['X-Product'].to_sym
class_name = (role.to_s + 'RegistrationService').camelize
class_name.constantize.call params: @params
end
def call!
validate
call
end
def validate
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment