Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the filtering of attributes validated with SchemaValidations::Validators::NotNilValidator #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/schema_validations/active_record/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,26 @@ def create_schema_validations? #:nodoc:
end

def validate_logged(method, arg, opts={}) #:nodoc:
if _filter_validation(method, arg)
if _filter_validation(method, arg, opts)
msg = "[schema_validations] #{self.name}.#{method} #{arg.inspect}"
msg += ", #{opts.inspect[1...-1]}" if opts.any?
logger.debug msg if logger
send method, arg, opts
end
end

def _filter_validation(macro, name) #:nodoc:
def _filter_validation(macro, name, opts) #:nodoc:
config = schema_validations_config
types = [macro]
if match = macro.to_s.match(/^validates_(.*)_of$/)
types << match[1].to_sym

case macro.to_s
when /^validates_(.*)_of$/
types << Regexp.last_match[1].to_sym
when 'validates_with'
types << name
name = opts[:attributes].first
end

return false if config.only and not Array.wrap(config.only).include?(name)
return false if config.except and Array.wrap(config.except).include?(name)
return false if config.whitelist and Array.wrap(config.whitelist).include?(name)
Expand Down