Module: Phronomy::WorkflowContext::ClassMethods

Defined in:
lib/phronomy/workflow_context.rb

Instance Method Summary collapse

Instance Method Details

#field(name, type: :replace, default: nil) ⇒ Object

Defines a context field.

Parameters:

  • name (Symbol)
  • type (Symbol) (defaults to: :replace)

    :replace / :append / :merge

  • default (Object, Proc, nil) (defaults to: nil)

Raises:

  • (ArgumentError)

    if +default+ is a plain Array or Hash (use a Proc instead)



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/phronomy/workflow_context.rb', line 36

def field(name, type: :replace, default: nil)
  if default.is_a?(Array) || default.is_a?(Hash)
    raise ArgumentError,
      "Mutable default for field #{name.inspect} must be wrapped in a Proc " \
      "to avoid shared state across instances. " \
      "Use `default: -> { #{default.inspect} }` instead."
  end

  @fields[name] = {type: type, default: default}
  attr_accessor name
end

#fieldsObject



48
49
50
# File 'lib/phronomy/workflow_context.rb', line 48

def fields
  @fields
end