Class: Wheel::Config

Inherits:
ApplicationRecord show all
Defined in:
lib/wheel/config.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(context = {}) ⇒ Object

Evaluates the config value based on the given context



11
12
13
14
15
16
17
18
19
20
# File 'lib/wheel/config.rb', line 11

def evaluate(context = {})
  return typed_default_value unless enabled?
  return typed_default_value if conditions.blank?

  matching_condition = conditions.find do |condition|
    evaluate_condition(condition, context&.stringify_keys)
  end

  matching_condition ? type_cast_value(matching_condition['value']) : typed_default_value
end