module Roda::RodaPlugins::Monads
Makes `Roda` understand `Dry::Monads::Result` monad and provide results based on `Success` or `Failure` monad handler.
@see Monads::RequestMethods
@see Monads::InstanceMethods
@example
plugin :monads route do |r| r.on '/right' do Success('Alright!') end r.on '/left' do Failure('Wrong!') end r.on '/rack' do r.on '/right' do Success([:ok, {}, ['Alright!']]) end r.on '/left' do Failure('Wrong!') end end end
Public Class Methods
configure(app, *)
click to toggle source
Extends `app` with `Dry::Monads::Result::Mixin` to create monads easily @param [Roda] app
# File lib/roda/plugins/monads.rb, line 43 def self.configure(app, *) app.extend Dry::Monads::Result::Mixin app.include Dry::Monads::Result::Mixin app.either_matcher(:right, aliases: [:value]) { |either| match_right(either) } app.either_matcher(:left, aliases: [:status]) { |status| match_left(status) } app.either_matcher(:either) { |either| match_either(either) } app.either_matcher(:rack_either) { |value| match_rack_either(value) } end
load_dependencies(app, *)
click to toggle source
Loads `Dry::Monads` gem @param [Roda] app @raise [LoadError] if gem `dry-monads` cannot be loaded
# File lib/roda/plugins/monads.rb, line 37 def self.load_dependencies(app, *) app.plugin :symbol_status end