Class: ActiveSaga::Context

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_saga/context.rb

Overview

TODO Revisit impl.

Instance Method Summary collapse

Constructor Details

#initialize(payload = {}) ⇒ Context

Returns a new instance of Context.



10
11
12
# File 'lib/active_saga/context.rb', line 10

def initialize(payload = {})
  @payload = normalize(payload || {})
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/active_saga/context.rb', line 14

def [](key)
  @payload[key.to_sym]
end

#[]=(key, value) ⇒ Object



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

def []=(key, value)
  @payload[key.to_sym] = normalize(value)
end

#dupObject



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

def dup
  self.class.new(to_h)
end

#each(&block) ⇒ Object



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

def each(&block)
  @payload.each(&block)
end

#fetch(key, *args) ⇒ Object



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

def fetch(key, *args)
  @payload.fetch(key.to_sym, *args)
end

#merge!(other_hash) ⇒ Object



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

def merge!(other_hash)
  other_hash.each_pair { |k, v| self[k] = v }
  self
end

#to_hObject



31
32
33
# File 'lib/active_saga/context.rb', line 31

def to_h
  deep_dup(@payload)
end