class Mixture::Validate::Presence
Checks that a value is present.
Public Instance Methods
validate(record, attribute, value)
click to toggle source
Performs the validation.
@param (see Base#validate
) @return (see Base#validate
) @raise [ValidationError] If {#empty?} returns true.
Calls superclass method
Mixture::Validate::Base#validate
# File lib/mixture/validate/presence.rb, line 14 def validate(record, attribute, value) super error("Value is empty") if empty? end
Private Instance Methods
empty?()
click to toggle source
Determins if the given value is empty. If it's not nil, and it responds to `empty?`, it returns the value of `empty?`; otherwise, it returns the value of `nil?`.
@return [Boolean]
# File lib/mixture/validate/presence.rb, line 26 def empty? @value.nil? || (@value.respond_to?(:empty?) && @value.empty?) end