Skip to content

Instantly share code, notes, and snippets.

@manojmj92
Created August 4, 2018 08:19
Show Gist options
  • Save manojmj92/6ecb4ae47266095d051f0b2df1fe49f3 to your computer and use it in GitHub Desktop.
Save manojmj92/6ecb4ae47266095d051f0b2df1fe49f3 to your computer and use it in GitHub Desktop.
# 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