Module: Validator

Defined in:
lib/decoractors/valid.rb

Instance Method Summary collapse

Instance Method Details

#convert_errors_response(error_list) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/decoractors/valid.rb', line 16

def convert_errors_response(error_list)
	errors = []
	error_list.each do |key, value|
		errors << {field: key, message: value}
	end
	errors
end

#validate(params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/decoractors/valid.rb', line 4

def validate params={}
  lambda {|self_model, *args, &blk|
    puts "Validate"
    check_validate = self_model.check_validate(*args, &blk) # check validation and return [true]/[false, errors]
    if check_validate[0]
    	true
    else
    	check_validate[2].response_with_error(CommonError::InvalidData, check_validate[1])
    end
  }
end