Class: Himari::Decisions::Claims
- Inherits:
-
Base
- Object
- Base
- Himari::Decisions::Claims
show all
- Defined in:
- lib/himari/decisions/claims.rb
Defined Under Namespace
Classes: AlreadyInitializedError, Context, UninitializedError
Instance Attribute Summary collapse
Attributes inherited from Base
#effect, #effect_comment, #effect_suggestion, #effect_user_facing_message, #rule_name
Instance Method Summary
collapse
Methods inherited from Base
#allow!, allow_effects, #continue!, #decide!, #deny!, #evolve, #set_rule_name, #skip!, #to_h, valid_effects
Constructor Details
#initialize(claims: nil, user_data: nil, lifetime: nil) ⇒ Claims
Returns a new instance of Claims.
16
17
18
19
20
21
|
# File 'lib/himari/decisions/claims.rb', line 16
def initialize(claims: nil, user_data: nil, lifetime: nil)
super()
@claims = claims
@user_data = user_data
@lifetime = lifetime
end
|
Instance Attribute Details
#lifetime ⇒ Object
Returns the value of attribute lifetime.
23
24
25
|
# File 'lib/himari/decisions/claims.rb', line 23
def lifetime
@lifetime
end
|
Instance Method Details
#as_log ⇒ Object
33
34
35
|
# File 'lib/himari/decisions/claims.rb', line 33
def as_log
to_h.merge(claims: @claims)
end
|
#claims ⇒ Object
49
50
51
52
53
54
|
# File 'lib/himari/decisions/claims.rb', line 49
def claims
unless @claims
raise UninitializedError, "Claims uninitialized; use decision.initialize_claims! to declare claims first (or rule order might be unintentional)" unless @claims
end
@claims
end
|
#initialize_claims!(claims = {}) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/himari/decisions/claims.rb', line 41
def initialize_claims!(claims = {})
if @claims
raise AlreadyInitializedError, "Claims already initialized; use decision.claims to make modification, or rule might be behaving wrong"
end
@claims = claims.dup
@user_data = {}
end
|
#output ⇒ Object
37
38
39
|
# File 'lib/himari/decisions/claims.rb', line 37
def output
Himari::SessionData.make(claims: claims, user_data: user_data, lifetime: lifetime)
end
|
#to_evolve_args ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/himari/decisions/claims.rb', line 25
def to_evolve_args
{
claims: @claims.dup,
user_data: @user_data.dup,
lifetime: @lifetime&.to_i,
}
end
|
#user_data ⇒ Object
56
57
58
59
|
# File 'lib/himari/decisions/claims.rb', line 56
def user_data
claims @user_data
end
|