Class: MiniCamel::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_camel/exchange.rb

Instance Method Summary collapse

Instance Method Details

#context_fetch(field_name, default: nil) ⇒ Object



61
62
63
# File 'lib/mini_camel/exchange.rb', line 61

def context_fetch(field_name, default: nil)
  context.fetch(field_name, default: default)
end

#failure?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/mini_camel/exchange.rb', line 16

def failure?
  !success?
end

#on(modifier) {|result| ... } ⇒ Object

Yields:

  • (result)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
# File 'lib/mini_camel/exchange.rb', line 20

def on(modifier)
  raise ArgumentError, "Unkown modifier '#{modifier}'" unless modifier.in? [:success, :failure]

  yield result if modifier == :success && success?
  yield error  if modifier == :failure && failure?

  self
end

#result_or_else(fallback) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/mini_camel/exchange.rb', line 29

def result_or_else(fallback)
  if success?
    result
  else
    ExchangeResult.new(fallback)
  end
end

#result_or_else_fail!Object



41
42
43
44
45
46
47
# File 'lib/mini_camel/exchange.rb', line 41

def result_or_else_fail!
  if success?
    result
  else
    raise ExchangeFailure.new("Exchange failed!", error)
  end
end

#result_or_else_nilObject



37
38
39
# File 'lib/mini_camel/exchange.rb', line 37

def result_or_else_nil
  result if success?
end

#result_or_else_tryObject



49
50
51
52
53
54
55
# File 'lib/mini_camel/exchange.rb', line 49

def result_or_else_try
  if success?
    result
  else
    yield error
  end
end

#set_error(exchange_error) ⇒ Object



69
70
71
# File 'lib/mini_camel/exchange.rb', line 69

def set_error(exchange_error)
  self.error = exchange_error
end

#set_result(exchange_result) ⇒ Object



65
66
67
# File 'lib/mini_camel/exchange.rb', line 65

def set_result(exchange_result)
  self.result = exchange_result
end

#success?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/mini_camel/exchange.rb', line 12

def success?
  error.nil?
end

#update_context(params = {}) ⇒ Object



57
58
59
# File 'lib/mini_camel/exchange.rb', line 57

def update_context(params = {})
  context.update(params)
end