class Errapi::Validations::Presence
Constants
- BLANK_REGEXP
Public Instance Methods
validate(value, context, options = {})
click to toggle source
# File lib/errapi/validations/presence.rb, line 7 def validate value, context, options = {} if reason = check(value, options.fetch(:value_set, true)) context.add_error reason: reason end end
Private Instance Methods
check(value, value_set)
click to toggle source
# File lib/errapi/validations/presence.rb, line 17 def check value, value_set # TODO: allow customization (e.g. values that are not required, booleans, etc) if !value_set :missing elsif value.nil? :null elsif value.respond_to?(:empty?) && value.empty? :empty elsif value_blank? value :blank end end
value_blank?(value)
click to toggle source
# File lib/errapi/validations/presence.rb, line 30 def value_blank? value if value.respond_to? :blank? value.blank? elsif value.kind_of? String BLANK_REGEXP === value else false end end