Class: Predicates::Required

Inherits:
Base
  • Object
show all
Defined in:
lib/predicates/required.rb

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

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

Returns:

  • (Boolean)


11
12
13
# File 'lib/predicates/required.rb', line 11

def allow_empty?
  false
end

#error_messageObject



15
16
17
# File 'lib/predicates/required.rb', line 15

def error_message
  @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