Class: ActiveModel::Validations::StateHistoryEntryValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/active_model/validations/state_history_entry_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ StateHistoryEntryValidator

Returns a new instance of StateHistoryEntryValidator.



5
6
7
8
9
10
11
# File 'lib/active_model/validations/state_history_entry_validator.rb', line 5

def initialize(options = {})
  super

  @start = options[:start] || :start
  @end   = options[:end]   || :end
  @allow = options[:allow] || []
end

Instance Method Details

#validate(record) ⇒ Object



13
14
15
16
17
18
# File 'lib/active_model/validations/state_history_entry_validator.rb', line 13

def validate(record)
  non_zero?(record)         unless @allow.include? :zero_duration
  start_before_end?(record) unless @allow.include? :end_before_start

  return
end