class SetLanguage
include Dry::Effects::Handler.Reader(:lang, type: Symbol)
def call(env)
# detect_lang has to return a Symbol
with_lang(detect_lang(env)) { @app.(env) }
end
end
class Authenticate
include Dry::Effects::Handler.State(:current_user, type: Entities::User)
def call(env)
with_user do
# will raise if authenticate returns anything different from Entities::User
self.user = authenticate(env)
@app.(env)
end
end
end
Normally, you want state to be typed: