lib/zen/validation.rb in zen-0.2.5 vs lib/zen/validation.rb in zen-0.2.6
- old
+ new
@@ -6,13 +6,13 @@
# The Validation module is a very basic validation framework that's used by various
# internal modules/classes such as Zen::Plugin and Zen::Package.
#
# ## Usage
#
- # Using the module is pretty simple. Include it, specify the validation rules in a
+ # Using the module is pretty simple. Include it, specify the validation rules in a
# method and call it. All official modules and classes use a method called "validate"
- # but you're free to name it whatever you want. A basic example looks like the
+ # but you're free to name it whatever you want. A basic example looks like the
# following:
#
# class Something
# include Zen::Validation
#
@@ -25,11 +25,10 @@
#
# @author Yorick Peterse
# @since 0.2.5
#
module Validation
-
##
# Checks if the specified attributes exist and aren't set to nil.
#
# @example
# validates_presence(:name)
@@ -72,11 +71,11 @@
def validates_length(attribute, options)
value = send(attribute)
if !value.respond_to?(:length)
raise(
- ValidationError,
+ ValidationError,
"The length of \"#{attribute}\" can't be checked as the method \"length\" " +
"doesn't exist."
)
end
@@ -105,11 +104,11 @@
# @since 0.2.5
# @param [Hash/Symbol] attribute The name of the attribute to validate or a hash
# containing all the attributes and their regular expressions.
# @param [Regexp] regexp The regular expression to use when validating a single
# attribute.
- # @raise [ValidationError] Raised when one of the attributes doesn't matches the
+ # @raise [ValidationError] Raised when one of the attributes doesn't matches the
# regular expression.
#
def validates_format(attribute, regexp = nil)
if attribute.class != Hash
attribute = {attribute => regexp}
@@ -137,13 +136,12 @@
# @param [String/Symbol] attribute The attribute to validate.
# @raise [ValidationError] Raised when one of the paths didn't exist.
#
def validates_filepath(attribute)
path = send(attribute)
-
+
if !File.exist?(path)
raise(ValidationError, "The path #{path} in \"#{attribute}\" doesn't exist.")
end
end
-
- end
-end
+ end # Validation
+end # Zen