Class: Predicates::Required
Overview
Marks an attribute as being required. This is really just a shortcut for using the or_empty? setting.
Example:
class Comment < ActiveRecord::Base
has_one :owner
subject_is_required
owner_is_required
end
Instance Attribute Summary
Attributes inherited from Base
#full_message, #or_empty, #validate_if, #validate_on
Instance Method Summary collapse
-
#allow_empty? ⇒ Boolean
this permanently sets :or_empty to false.
- #error_message ⇒ Object
- #validate(value, record) ⇒ Object
Methods inherited from Base
#error, #error_binds, #initialize, #normalize, #to_human
Constructor Details
This class inherits a constructor from Predicates::Base
Instance Method Details
#allow_empty? ⇒ Boolean
this permanently sets :or_empty to false
11 12 13 |
# File 'lib/predicates/required.rb', line 11 def allow_empty? false end |
#error_message ⇒ Object
15 16 17 |
# File 'lib/predicates/required.rb', line 15 def @error_message || :required end |
#validate(value, record) ⇒ Object
19 20 21 |
# File 'lib/predicates/required.rb', line 19 def validate(value, record) !value.blank? end |