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



25
26
27
28
29
30
31
# File 'lib/validates_timeliness/orm/mongoid.rb', line 25

def timeliness_attribute_type(attr_name)
  {
    Date => :date,
    Time => :time,
    DateTime => :datetime
  }[fields[database_field_name(attr_name)].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.



18
19
20
21
22
23
# File 'lib/validates_timeliness/orm/mongoid.rb', line 18

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