Module: ValidatesTimeliness::ORM::Mongoid::ClassMethods

Defined in:
lib/validates_timeliness/orm/mongoid.rb

Overview

You need define the fields before you define the validations. It is best to use the plugin parser to avoid errors on a bad field value in Mongoid. Parser will return nil rather than error.

Instance Method Summary collapse

Instance Method Details

#timeliness_attribute_type(attr_name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/validates_timeliness/orm/mongoid.rb', line 21

def timeliness_attribute_type(attr_name)
  {
    Date => :date,
    Time => :datetime,
    DateTime => :datetime
  }[fields[attr_name.to_s].type] || :datetime
end

#timeliness_validation_for(attr_names, type) ⇒ Object

Mongoid has no bulk attribute method definition hook. It defines them with each field definition. So we likewise define them after each validation is defined.



16
17
18
19
# File 'lib/validates_timeliness/orm/mongoid.rb', line 16

def timeliness_validation_for(attr_names, type)
  super
  attr_names.each { |attr_name| define_timeliness_write_method(attr_name) }
end