Class: Operandi::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/operandi/message.rb

Overview

Represents a single error or warning message.

Examples:

Creating a message

message = Message.new(:name, "can't be blank", break: true)
message.key    # => :name
message.text   # => "can't be blank"
message.break? # => true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, text, opts = {}) ⇒ Message

Create a new message.

Parameters:

  • key (Symbol)

    the key/field this message belongs to

  • text (String)

    the message text

  • opts (Hash) (defaults to: {})

    additional options

Options Hash (opts):

  • :break (Boolean)

    whether to stop step execution

  • :rollback (Boolean)

    whether to rollback the transaction



25
26
27
28
29
# File 'lib/operandi/message.rb', line 25

def initialize(key, text, opts = {})
  @key = key
  @text = text
  @opts = opts
end

Instance Attribute Details

#keySymbol (readonly)

Returns the key/field this message belongs to.

Returns:

  • (Symbol)

    the key/field this message belongs to



13
14
15
# File 'lib/operandi/message.rb', line 13

def key
  @key
end

#textString (readonly)

Returns the message text.

Returns:

  • (String)

    the message text



16
17
18
# File 'lib/operandi/message.rb', line 16

def text
  @text
end

Instance Method Details

#break?Boolean

Check if this message should stop step execution.

Returns:

  • (Boolean)

    true if break option was set



34
35
36
# File 'lib/operandi/message.rb', line 34

def break?
  @opts[:break]
end

#rollback?Boolean

Check if this message should trigger a transaction rollback.

Returns:

  • (Boolean)

    true if rollback option was set



41
42
43
# File 'lib/operandi/message.rb', line 41

def rollback?
  @opts[:rollback]
end

#to_sString

Return the message text.

Returns:

  • (String)

    the message text



48
49
50
# File 'lib/operandi/message.rb', line 48

def to_s
  text
end