Class: ActionSequence::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/action_sequence/context.rb

Overview

Context container to hold state for an Sequence of Actions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_context: {}) ⇒ Context

Returns a new instance of Context.



11
12
13
14
# File 'lib/action_sequence/context.rb', line 11

def initialize(initial_context: {})
  @context = initial_context
  @error_message = nil
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



9
10
11
# File 'lib/action_sequence/context.rb', line 9

def error_message
  @error_message
end

Instance Method Details

#add_to_context!(hash) ⇒ Object



16
17
18
# File 'lib/action_sequence/context.rb', line 16

def add_to_context!(hash)
  context.merge!(hash)
end

#fail_context!(error_message) ⇒ Object



28
29
30
# File 'lib/action_sequence/context.rb', line 28

def fail_context!(error_message)
  @error_message = error_message
end

#failed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/action_sequence/context.rb', line 20

def failed?
  !error_message.nil?
end

#fetch(key, default) ⇒ Object



32
33
34
# File 'lib/action_sequence/context.rb', line 32

def fetch(key, default)
  context.fetch(key, default)
end

#success?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/action_sequence/context.rb', line 24

def success?
  error_message.nil?
end