Class: DelayHenka::WhetherSchedule

Inherits:
Object
  • Object
show all
Defined in:
app/services/delay_henka/whether_schedule.rb

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ WhetherSchedule

Returns a new instance of WhetherSchedule.



4
5
6
# File 'app/services/delay_henka/whether_schedule.rb', line 4

def initialize(record)
  @record = record
end

Instance Method Details

#evaluate_decision(attribute, new_val) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'app/services/delay_henka/whether_schedule.rb', line 14

def evaluate_decision(attribute, new_val)
  Keka.run do
    old_val = record.public_send(attribute)
    record.public_send("#{attribute}=", new_val)
    Keka.err_if! old_val == record.public_send(attribute)
    Keka.ok_if! record.valid?
    Keka.err_if! true, record.errors.full_messages.join(', ')
  end
end

#make_decision(attribute, new_val) ⇒ Object



8
9
10
11
12
# File 'app/services/delay_henka/whether_schedule.rb', line 8

def make_decision(attribute, new_val)
  evaluate_decision(attribute, new_val).tap do
    @record.restore_attributes
  end
end