Module: Lotus::Validations
- Defined in:
- lib/lotus/validations.rb,
lib/lotus/validations/error.rb,
lib/lotus/validations/errors.rb,
lib/lotus/validations/version.rb,
lib/lotus/validations/attribute.rb,
lib/lotus/validations/coercions.rb,
lib/lotus/validations/validator.rb,
lib/lotus/validations/validation_set.rb,
lib/lotus/validations/attribute_definer.rb,
lib/lotus/validations/nested_attributes.rb,
lib/lotus/validations/blank_value_checker.rb
Overview
Lotus::Validations is a set of lightweight validations for Ruby objects.
Defined Under Namespace
Modules: AttributeDefiner, ClassMethods, Coercions Classes: Attribute, BlankValueChecker, Error, Errors, NestedAttributes, ValidationSet, Validator
Constant Summary collapse
- VERSION =
'0.4.0'.freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
private
Override Ruby’s hook for modules.
Instance Method Summary collapse
-
#each(&blk) {|attribute, value| ... } ⇒ Object
Iterates thru the defined attributes and their values.
-
#errors ⇒ Lotus::Validations::Errors
Validation errors.
-
#invalid? ⇒ TrueClass, FalseClass
Checks if the current data doesn’t satisfies the defined validations.
-
#to_h ⇒ Hash
Returns a Hash with the defined attributes as symbolized keys, and their relative values.
-
#valid? ⇒ TrueClass, FalseClass
Checks if the current data satisfies the defined validations.
-
#validate ⇒ Errors
private
Validates the object.
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Ruby’s hook for modules.
23 24 25 26 27 28 |
# File 'lib/lotus/validations.rb', line 23 def self.included(base) base.class_eval do extend ClassMethods include AttributeDefiner end end |
Instance Method Details
#each(&blk) {|attribute, value| ... } ⇒ Object
Iterates thru the defined attributes and their values
265 266 267 |
# File 'lib/lotus/validations.rb', line 265 def each(&blk) to_h.each(&blk) end |
#errors ⇒ Lotus::Validations::Errors
Validation errors
221 222 223 |
# File 'lib/lotus/validations.rb', line 221 def errors @errors ||= Errors.new end |
#invalid? ⇒ TrueClass, FalseClass
Checks if the current data doesn’t satisfies the defined validations
241 242 243 |
# File 'lib/lotus/validations.rb', line 241 def invalid? !valid? end |
#to_h ⇒ Hash
Returns a Hash with the defined attributes as symbolized keys, and their relative values.
275 276 277 278 279 280 |
# File 'lib/lotus/validations.rb', line 275 def to_h # TODO remove this symbolization when we'll support Ruby 2.2+ only Utils::Hash.new( @attributes ).deep_dup.symbolize!.to_h end |
#valid? ⇒ TrueClass, FalseClass
Checks if the current data satisfies the defined validations
230 231 232 233 234 |
# File 'lib/lotus/validations.rb', line 230 def valid? validate errors.empty? end |
#validate ⇒ Errors
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates the object.
253 254 255 256 |
# File 'lib/lotus/validations.rb', line 253 def validate validator = Validator.new(defined_validations, read_attributes, errors) validator.validate end |