Class: OverlapValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- OverlapValidator
- Defined in:
- lib/validates_overlap/overlap_validator.rb
Constant Summary collapse
- BEGIN_OF_UNIX_TIME =
Time.at(-2_147_483_648).to_datetime
- END_OF_UNIX_TIME =
Time.at(2_147_483_648).to_datetime
Instance Attribute Summary collapse
-
#scoped_model ⇒ Object
Returns the value of attribute scoped_model.
-
#sql_conditions ⇒ Object
Returns the value of attribute sql_conditions.
-
#sql_values ⇒ Object
Returns the value of attribute sql_values.
Instance Method Summary collapse
-
#initialize(args) ⇒ OverlapValidator
constructor
A new instance of OverlapValidator.
- #validate(record) ⇒ Object
Constructor Details
#initialize(args) ⇒ OverlapValidator
Returns a new instance of OverlapValidator.
13 14 15 16 17 |
# File 'lib/validates_overlap/overlap_validator.rb', line 13 def initialize(args) attributes_are_range(args[:attributes]) super end |
Instance Attribute Details
#scoped_model ⇒ Object
Returns the value of attribute scoped_model.
11 12 13 |
# File 'lib/validates_overlap/overlap_validator.rb', line 11 def scoped_model @scoped_model end |
#sql_conditions ⇒ Object
Returns the value of attribute sql_conditions.
9 10 11 |
# File 'lib/validates_overlap/overlap_validator.rb', line 9 def sql_conditions @sql_conditions end |
#sql_values ⇒ Object
Returns the value of attribute sql_values.
10 11 12 |
# File 'lib/validates_overlap/overlap_validator.rb', line 10 def sql_values @sql_values end |
Instance Method Details
#validate(record) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/validates_overlap/overlap_validator.rb', line 19 def validate(record) initialize_query(record, ) if overlapped_exists? if [:load_overlapped] record.instance_variable_set(:@overlapped_records, get_overlapped) end if record.respond_to? attributes.first if [:message_title].is_a?(Array) [:message_title].each do |key| record.errors.add(key, [:message_content] || :overlap) end else record.errors.add([:message_title] || attributes.first, [:message_content] || :overlap) end else record.errors.add([:message_title] || :base, [:message_content] || :overlap) end end end |