valid
Advanced tools
| module Validation | ||
| module Rule | ||
| class URI | ||
| def initialize(parts=[:host]) | ||
| @required_parts = parts | ||
| end | ||
| def error_key | ||
| :uri | ||
| end | ||
| def params | ||
| {:required_elements => @required_parts} | ||
| end | ||
| def valid_value?(uri_string) | ||
| begin | ||
| uri = URI(uri_string) | ||
| @required_parts.each do |part| | ||
| if uri.send(part).nil? || uri.send(part).empty? | ||
| return false | ||
| end | ||
| end | ||
| true | ||
| rescue ::URI::InvalidURIError => e | ||
| return false | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
@@ -56,4 +56,15 @@ module Validation | ||
| valid = true | ||
| all_rules = {} | ||
| rules.each_pair do |field, rules| | ||
| if self.instance_of?(Validation::Validator) | ||
| # use the normal instance variable | ||
| all_rules = self.rules | ||
| elsif self.is_a?(Validation::Validator) # inherited "stand-alone" validator | ||
| # in this case the rules have been defined in the class instance | ||
| # variable '@rules' since they were defined during the class definition | ||
| all_rules = self.class.rules | ||
| end | ||
| all_rules.each_pair do |field, rules| | ||
| if ! @obj.respond_to?(field) | ||
@@ -60,0 +71,0 @@ raise InvalidKey |
| module Validation | ||
| VERSION = '0.3.0' | ||
| VERSION = '0.3.1' | ||
| end |