lib/lotus/validations.rb in lotus-validations-0.3.1 vs lib/lotus/validations.rb in lotus-validations-0.3.2
- old
+ new
@@ -196,10 +196,30 @@
# # ],
# # :age=>[
# # #<Lotus::Validations::Error:0x007fe00cee30d8 @attribute=:age, @validation=:size, @expected=18..99, @actual=17>
# # ]
# # }>
+ #
+ # @example Invalid attributes
+ # require 'lotus/validations'
+ #
+ # class Post
+ # include Lotus::Validations
+ #
+ # attribute :title, presence: true
+ # end
+ #
+ # post = Post.new
+ # post.invalid? # => true
+ #
+ # post.errors
+ # # => #<Lotus::Validations::Errors:0x2931522b
+ # # @errors={
+ # # :title=>[
+ # # #<Lotus::Validations::Error:0x662706a7 @actual=nil, @attribute_name="title", @validation=:presence, @expected=true, @namespace=nil, @attribute="title">
+ # # ]
+ # # }>
def errors
@errors ||= Errors.new
end
# Checks if the current data satisfies the defined validations
@@ -209,9 +229,18 @@
# @since 0.1.0
def valid?
validate
errors.empty?
+ end
+
+ # Checks if the current data doesn't satisfies the defined validations
+ #
+ # @return [TrueClass,FalseClass] the result of the validations
+ #
+ # @since 0.3.2
+ def invalid?
+ !valid?
end
# Validates the object.
#
# @return [Errors]