module Idcf::Cli::Controller::Include::Validate
validate methods
Protected Instance Methods
do_validate(o)
click to toggle source
validate do
@param o [Hahs] @return Hash or nil
# File lib/idcf/cli/controller/include/validate.rb, line 17 def do_validate(o) err = first_validate(o) return nil if err.empty? make_validation_error(err) end
first_validate(o)
click to toggle source
first validate
@param o [Hash] options @return Hash or nil
# File lib/idcf/cli/controller/include/validate.rb, line 27 def first_validate(o) validator = make_validate(o, @cmd) validator.valid? ? [] : validator.errors.messages end
load_validate(paths, o)
click to toggle source
load validate
@param paths [Array] @param o [Hash] Validator @return class @raise
# File lib/idcf/cli/controller/include/validate.rb, line 54 def load_validate(paths, o) paths.each do |path| begin require path return path.classify.constantize.new(o) rescue LoadError next end end cli_error('Validate load error') end
make_validate(o, command)
click to toggle source
make validate
@paeram o [Hash] options @param command [String] @return ActiveModel
# File lib/idcf/cli/controller/include/validate.rb, line 37 def make_validate(o, command) service = self.class.to_s.underscore.split('/').pop path = Idcf::Cli::Conf::Const::VALIDATOR_DIR_PATH paths = [ "#{path}/#{service}/#{command}", "#{path}/#{service}/base", "#{path}/base" ] load_validate(paths, o) end
make_validation_error(errors)
click to toggle source
make validation error
@override @param errors [Hash] @return Hash
# File lib/idcf/cli/controller/include/validate.rb, line 71 def make_validation_error(errors) err = {} errors.each do |k, v| err[k] = "#{Idcf::Cli::Conf::Const::LOCAL_ERROR_PREFIX}#{v}" end result = make_base_response result[:status] = 400 result[:message] = err result end