lib/ratatouille/ratifier.rb in ratatouille-1.4.2 vs lib/ratatouille/ratifier.rb in ratatouille-1.4.3
- old
+ new
@@ -38,11 +38,11 @@
# Name of instance
#
# @return [String]
def name
@name ||= @ratifiable_object.class.to_s
- end
+ end#name
# Set name of instance
#
# @param [String] namein
@@ -51,26 +51,26 @@
case namein
when String
@name = namein unless namein.blank?
end
@name
- end
+ end#name=
# Add validation error. Useful for custom validations.
# @param [String] err_in
# @param [String] context
# @return [void]
- def validation_error(err_in, context="/")
+ def validation_error(err_in, context="/" )
case err_in
when String
return if err_in.blank?
@errors[context] = [] unless @errors[context]
- @errors[context] << "#{@name}: #{err_in}"
+ @errors[context] << err_in
end
rescue Exception => e
- @errors["/"] << "#{@name}: #{e.message}"
+ @errors[context] << "#{e.message}"
end#validation_error
# Does the object pass all validation logic?
#
@@ -102,11 +102,11 @@
when Hash, Array then errors_array(e)
when String then e
else []
end
- all_errs << namespace_error_array(item_errs, "[#{i}]")
+ all_errs << namespace_error_array(item_errs, "#{i}")
all_errs.flatten!
end
when Hash
item.each_pair do |k,v|
pair_errs = case v
@@ -157,11 +157,11 @@
unless @unwrap_block == true
case @ratifiable_object
when TrueClass, FalseClass
# OK to enter block
else
- validation_error("object is not a boolean")
+ validation_error("#{name} is not a boolean")
return
end
end
instance_eval(&block) if block_given?
@@ -202,17 +202,17 @@
# Perform no validation logic
# Skip to block evaluation
when id.to_s =~ /^is_not_(.*)$/
if @ratifiable_object.respond_to?("#{$1}?")
if @ratifiable_object.send("#{$1}?") == true
- validation_error("is #{$1}")
+ validation_error("#{name} is #{$1}")
return
end
end
when id.to_s =~ /^is_(.*)$/
if @ratifiable_object.respond_to?("#{$1}?")
if @ratifiable_object.send("#{$1}?") == false
- validation_error("is not #{$1}")
+ validation_error("#{name} is not #{$1}")
return
end
end
else
begin