Class: Custodian::Core::Custody

Inherits:
ApplicationRecord show all
Defined in:
app/models/custodian/core/custody.rb

Constant Summary collapse

VALIDITY_TYPES =
%w[eternal fixed_term punctual].freeze
STATUSES =
%w[active at_risk broken expired].freeze

Instance Method Summary collapse

Instance Method Details

#applies_to?(node) ⇒ Boolean

Answers only the exclusion question: is this node repudiated, or does it have an "exclude" rule? It does NOT interpret limit_pct/limit_amount rule values (i.e. it doesn't decide how much of the demand applies) - that quantitative interpretation is the Adjuster's job, in a later step.

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'app/models/custodian/core/custody.rb', line 26

def applies_to?(node)
  return false if repudiated_nodes.exists?(node: node)
  return false if node_rules.exists?(node: node, rule_type: "exclude")

  true
end

#at_risk?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/custodian/core/custody.rb', line 33

def at_risk?
  status == "at_risk"
end

#currently_valid?(at_time = Time.current) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/custodian/core/custody.rb', line 50

def currently_valid?(at_time = Time.current)
  return false if %w[broken expired].include?(status)

  case validity_type
  when "eternal"
    true
  when "fixed_term"
    fixed_term_valid_at?(at_time)
  when "punctual"
    punctual_valid_at?(at_time)
  end
end

#healthcheck(at_time = Time.current) ⇒ Object



41
42
43
44
45
46
47
48
# File 'app/models/custodian/core/custody.rb', line 41

def healthcheck(at_time = Time.current)
  return :broken if status == "broken"
  return :expired if status == "expired"
  return :expired unless currently_valid?(at_time)
  return :at_risk if at_risk?

  :active
end

#trustworthy?(at_time = Time.current) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/custodian/core/custody.rb', line 37

def trustworthy?(at_time = Time.current)
  currently_valid?(at_time) && !at_risk?
end