lib/scrivener/validations.rb in scrivener-0.2.0 vs lib/scrivener/validations.rb in scrivener-0.3.0
- old
+ new
@@ -23,17 +23,10 @@
# presenter layer.
# 3. It should be easy to write your own validation routine.
#
# Other validations are simply added on a per-model or per-project basis.
#
- # If you want other validations you may want to take a peek at Ohm::Contrib
- # and all of the validation modules it provides.
- #
- # @see http://cyx.github.com/ohm-contrib/doc/Ohm/WebValidations.html
- # @see http://cyx.github.com/ohm-contrib/doc/Ohm/NumberValidations.html
- # @see http://cyx.github.com/ohm-contrib/doc/Ohm/ExtraValidations.html
- #
# @example
#
# class Quote
# attr_accessor :title
# attr_accessor :price
@@ -115,21 +108,18 @@
# when the validation fails.
def assert_present(att, error = [att, :not_present])
assert(!send(att).to_s.empty?, error)
end
- # Checks if all the characters of an attribute is a digit. If you want to
- # verify that a value is a decimal, try looking at Ohm::Contrib's
- # assert_decimal assertion.
+ # Checks if all the characters of an attribute is a digit.
#
# @param [Symbol] att The attribute you wish to verify the numeric format.
# @param [Array<Symbol, Symbol>] error The error that should be returned
# when the validation fails.
- # @see http://cyx.github.com/ohm-contrib/doc/Ohm/NumberValidations.html
def assert_numeric(att, error = [att, :not_numeric])
if assert_present(att, error)
- assert_format(att, /\A\d+\z/, error)
+ assert_format(att, /\A\-?\d+\z/, error)
end
end
URL = /\A(http|https):\/\/([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|(2
5[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}
@@ -161,10 +151,10 @@
val = send(att).to_s
assert range.include?(val.length), error
end
end
- DECIMAL = /\A(\d+)?(\.\d+)?\z/
+ DECIMAL = /\A\-?(\d+)?(\.\d+)?\z/
def assert_decimal(att, error = [att, :not_decimal])
assert_format att, DECIMAL, error
end