Class: Laminar::Context

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

Overview

The environment and state of a particle (or flow) invocation. The context provides data required for a particle to do its job. A particle can modify the context during execution to return results, errors, etc.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



17
18
19
20
# File 'lib/laminar/context.rb', line 17

def initialize
  @halted = false
  @failed = false
end

Class Method Details

.build(context = {}) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/laminar/context.rb', line 8

def self.build(context = {})
  case context
  when self
    context
  else
    new.merge!(context || {})
  end
end

Instance Method Details

#fail!(context = {}) ⇒ Object



44
45
46
47
# File 'lib/laminar/context.rb', line 44

def fail!(context = {})
  @failed = true
  halt!(context)
end

#failed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/laminar/context.rb', line 26

def failed?
  @failed
end

#halt(context = {}) ⇒ Object



34
35
36
37
# File 'lib/laminar/context.rb', line 34

def halt(context = {})
  @halted = true
  merge!(context)
end

#halt!(context = {}) ⇒ Object

Raises:



39
40
41
42
# File 'lib/laminar/context.rb', line 39

def halt!(context = {})
  halt(context)
  raise ParticleStopped, self
end

#halted?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/laminar/context.rb', line 30

def halted?
  @halted
end

#success?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/laminar/context.rb', line 22

def success?
  !failed?
end