Skip to content

Instantly share code, notes, and snippets.

@NSLog0
Last active June 1, 2021 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NSLog0/afcbdea23e9b46b857f655083326feff to your computer and use it in GitHub Desktop.
Save NSLog0/afcbdea23e9b46b857f655083326feff to your computer and use it in GitHub Desktop.
use for article
class INotification
def send
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end
def body
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end
end
class EmailSender < INotification
# override method
def send
call_email_api(body)
end
def body
return '..... body .....'
end
end
class PushNotiSender < INotification
# override method
def send
call_firebase_api(body)
end
def body
return '..... body .....'
end
end
class SendNotiAdaptor
def initialize(type: )
@noti_type = type
end
def send
@adapter = nil
case @noti_type
when 'email'
@adapter = EmailSender.new
when 'push'
@adapter = PushNotiSender.new
else
raise ArgumentError, "not provided not type. please choose one of them"
end
client_caller(@adapter) if !@adapter.nil?
end
def client_caller(creator)
creator.send
end
end
SendNotiAdaptor.new(type: 'email').send
SendNotiAdaptor.new(type: 'push').send
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment