Class: SmartCore::Validator::RuleExecutionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/validator/rule_execution_context.rb

Defined Under Namespace

Classes: Failure

Instance Method Summary collapse

Constructor Details

#initialize(data, dependencies_to_bind) ⇒ RuleExecutionContext

Returns a new instance of RuleExecutionContext.



7
8
9
10
# File 'lib/smart_core/validator/rule_execution_context.rb', line 7

def initialize(data, dependencies_to_bind)
  self.data = data
  bind_to_self!(dependencies_to_bind)
end

Instance Method Details

#execute!(rule) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/smart_core/validator/rule_execution_context.rb', line 12

def execute!(rule)
  self.value = rule.value_from(data)
  instance_eval(&rule) if rule.executable?(data)
  nil
rescue Failure => e
  Result.new(rule.checked_attr, e.code).freeze
end