Class: DeadlineValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/task-manager/deadline_validator.rb

Overview

ActiveModel 必须包含type或class_name_type(plan_type)属性

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/task-manager/deadline_validator.rb', line 3

def validate_each(record, attribute, value)
  type = get_type(record)
  return unless type

  names = []
  case type.to_sym
  when :daily
    names = [:hour, :minute]
  when :weekly, :monthly
    names = [:hour, :minute, :day]
  when :quarterly, :yearly
    names = [:hour, :minute, :day, :month]
  end

  validate_deadline_of(record, attribute, value, names)
end