Module: ServiceActor::Defaultable

Defined in:
lib/service_actor/defaultable.rb

Overview

Adds the ‘default:` option to inputs. Accepts regular values and lambdas. If no default is set and the value has not been given, raises an error.

Example:

class MultiplyThing < Actor
  input :counter, default: 1
  input :multiplier, default: -> { rand(1..10) }
end

class MultiplyThing < Actor
  input :counter,
        default: {
          is: 1,
          message: "Counter is required"
        }

  input :multiplier,
        default: {
          is: -> { rand(1..10) },
          message: (lambda do |input_key:, actor:|
            "Input \"#{input_key}\" is required"
          end)
        }
end

Defined Under Namespace

Modules: PrependedMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



30
31
32
# File 'lib/service_actor/defaultable.rb', line 30

def included(base)
  base.prepend(PrependedMethods)
end