Created
August 4, 2018 08:19
-
-
Save manojmj92/6ecb4ae47266095d051f0b2df1fe49f3 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
# Without delegation | |
class MyInteractor | |
include Interactor | |
def call | |
if context.email.match(/^[a-z]+.\@reflektive\.com$/i) | |
puts "Welcome, #{context.name} from Reflektive!" | |
end | |
end | |
end | |
# Using explicit delegation with ActiveSupport delegate | |
class MyInteractor | |
include Interactor | |
delegate :email, :name, to: :context | |
def call | |
if email.match(/^[a-z]+.\@reflektive\.com$/i) | |
puts "Welcome, #{name} from Reflektive!" | |
end | |
end | |
end | |
# When `requires` automatically handles the delegation. | |
class MyInteractor < BaseInteractor | |
requires :email, :name | |
def call | |
if email.match(/^[a-z]+.\@reflektive\.com$/i) | |
puts "Welcome, #{name} from Reflektive!" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment