Class: Smith::Context
- Inherits:
-
Object
show all
- Defined in:
- lib/smith/context.rb,
lib/smith/context/session.rb,
lib/smith/context/state_injection.rb,
lib/smith/context/observation_masking.rb
Defined Under Namespace
Modules: ObservationMasking, StateInjection
Classes: Session
Class Method Summary
collapse
Class Method Details
.inherited(subclass) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/smith/context.rb', line 6
def inherited(subclass)
super
subclass.instance_variable_set(:@session_strategy, @session_strategy)
subclass.instance_variable_set(:@persist_keys, (@persist_keys || []).dup)
subclass.instance_variable_set(:@persist_mode, @persist_mode || :explicit)
subclass.instance_variable_set(:@persist_auto_seed, (@persist_auto_seed || []).dup)
subclass.instance_variable_set(:@inject_state, @inject_state)
end
|
.inject_state(&block) ⇒ Object
54
55
56
57
58
|
# File 'lib/smith/context.rb', line 54
def inject_state(&block)
return @inject_state unless block_given?
@inject_state = block
end
|
.persist(*keys, also: nil) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/smith/context.rb', line 21
def persist(*keys, also: nil)
if keys.empty? && also.nil?
return @persist_keys || []
end
if also && !keys.include?(:auto)
raise Smith::WorkflowError, ":also is only valid alongside :auto"
end
if keys.include?(:auto)
other_keys = keys.reject { |k| k == :auto }
unless other_keys.empty?
raise Smith::WorkflowError, "persist :auto must be the sole positional argument; got #{other_keys.inspect}"
end
@persist_mode = :auto
@persist_keys = []
@persist_auto_seed = Array(also).map(&:to_sym)
return @persist_auto_seed.dup
end
@persist_mode = :explicit
@persist_keys ||= []
@persist_keys.concat(keys)
end
|
.persist_auto_seed ⇒ Object
50
51
52
|
# File 'lib/smith/context.rb', line 50
def persist_auto_seed
@persist_auto_seed || []
end
|
.persist_mode ⇒ Object
46
47
48
|
# File 'lib/smith/context.rb', line 46
def persist_mode
@persist_mode || :explicit
end
|
.session_strategy(strategy = nil, **opts) ⇒ Object
15
16
17
18
19
|
# File 'lib/smith/context.rb', line 15
def session_strategy(strategy = nil, **opts)
return @session_strategy if strategy.nil?
@session_strategy = { strategy: strategy, **opts }
end
|