module SimpleForm::Helpers::Validators
Public Instance Methods
has_validators?()
click to toggle source
# File lib/simple_form/helpers/validators.rb, line 5 def has_validators? @has_validators ||= attribute_name && object.class.respond_to?(:validators_on) end
Private Instance Methods
action_validator_match?(validator)
click to toggle source
# File lib/simple_form/helpers/validators.rb, line 27 def action_validator_match?(validator) return true unless validator.options.include?(:on) case validator.options[:on] when :save true when :create !object.persisted? when :update object.persisted? end end
attribute_validators()
click to toggle source
# File lib/simple_form/helpers/validators.rb, line 11 def attribute_validators object.class.validators_on(attribute_name) end
conditional_validators?(validator)
click to toggle source
# File lib/simple_form/helpers/validators.rb, line 23 def conditional_validators?(validator) validator.options.include?(:if) || validator.options.include?(:unless) end
find_validator(kind)
click to toggle source
# File lib/simple_form/helpers/validators.rb, line 40 def find_validator(kind) attribute_validators.find { |v| v.kind == kind } if has_validators? end
reflection_validators()
click to toggle source
# File lib/simple_form/helpers/validators.rb, line 15 def reflection_validators reflection ? object.class.validators_on(reflection.name) : [] end
valid_validator?(validator)
click to toggle source
# File lib/simple_form/helpers/validators.rb, line 19 def valid_validator?(validator) !conditional_validators?(validator) && action_validator_match?(validator) end