module AdLint::Validation
Public Class Methods
included(class_or_module)
click to toggle source
# File lib/adlint/util.rb, line 158 def self.included(class_or_module) class_or_module.extend(self) end
Public Instance Methods
ensure_dir_presence_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 80 def ensure_dir_presence_of(*args) @validators ||= [] attr_names, opts = _attr_names_in(args), _options_in(args) allow_nil = opts[:allow_nil] attr_names.each do |attr_name| @validators.push(DirPresenceValidator.new(attr_name, allow_nil)) end self end
ensure_dirs_presence_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 90 def ensure_dirs_presence_of(*args) @validators ||= [] attr_names = _attr_names_in(args) attr_names.each do |attr_name| @validators.push(DirsPresenceValidator.new(attr_name)) end self end
ensure_exam_packages_presence_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 118 def ensure_exam_packages_presence_of(*args) @validators ||= [] attr_names = _attr_names_in(args) attr_names.each do |attr_name| @validators.push(ExamPackagesPresenceValidator.new(attr_name)) end self end
ensure_file_presence_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 70 def ensure_file_presence_of(*args) @validators ||= [] attr_names, opts = _attr_names_in(args), _options_in(args) allow_nil = opts[:allow_nil] attr_names.each do |attr_name| @validators.push(FilePresenceValidator.new(attr_name, allow_nil)) end self end
ensure_inclusion_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 99 def ensure_inclusion_of(*args) @validators ||= [] attr_names, opts = _attr_names_in(args), _options_in(args) vals = opts[:values] || [] attr_names.each do |attr_name| @validators.push(InclusionValidator.new(attr_name, vals)) end self end
ensure_numericality_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 57 def ensure_numericality_of(*args) @validators ||= [] attr_names, opts = _attr_names_in(args), _options_in(args) only_int = opts[:only_integer] ? true : false min = opts[:min] max = opts[:max] attr_names.each do |attr_name| @validators.push(NumericalityValidator.new(attr_name, only_int, min, max)) end self end
ensure_presence_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 48 def ensure_presence_of(*args) @validators ||= [] attr_names = _attr_names_in(args) attr_names.each do |attr_name| @validators.push(PresenceValidator.new(attr_name)) end self end
ensure_true_or_false_of(*args)
click to toggle source
# File lib/adlint/util.rb, line 109 def ensure_true_or_false_of(*args) @validators ||= [] attr_names = _attr_names_in(args) attr_names.each do |attr_name| @validators.push(TrueOrFalseValidator.new(attr_name)) end self end
ensure_validity_of(*args)
click to toggle source
NOTE: Host class must respond to entity_name.
# File lib/adlint/util.rb, line 39 def ensure_validity_of(*args) @validators ||= [] attr_names = _attr_names_in(args) attr_names.each do |attr_name| @validators.push(ObjectValidator.new(attr_name)) end self end
ensure_with(*args)
click to toggle source
# File lib/adlint/util.rb, line 127 def ensure_with(*args) @validators ||= [] attr_names, opts = _attr_names_in(args), _options_in(args) msg = opts[:message] || "is not valid." validator = opts[:validator] || lambda { |val| val } attr_names.each do |attr_name| @validators.push(CustomValidator.new(attr_name, msg, validator)) end self end
errors()
click to toggle source
# File lib/adlint/util.rb, line 150 def errors if self.class.validators self.class.validators.map { |validator| validator.errors }.flatten else [] end end
valid?()
click to toggle source
# File lib/adlint/util.rb, line 142 def valid? if self.class.validators self.class.validators.map { |validator| validator.execute(self) }.all? else true end end
validators()
click to toggle source
# File lib/adlint/util.rb, line 138 def validators @validators ||= [] end
Private Instance Methods
_attr_names_in(args)
click to toggle source
# File lib/adlint/util.rb, line 163 def _attr_names_in(args) args.select { |obj| obj.kind_of?(Symbol) } end
_options_in(args)
click to toggle source
# File lib/adlint/util.rb, line 167 def _options_in(args) args.find { |obj| obj.kind_of?(Hash) } || {} end