valid
Advanced tools
| module Validation | ||
| module Rule | ||
| class RegularExpression | ||
| def initialize(params) | ||
| @params = params | ||
| end | ||
| def error_key | ||
| :regular_expression | ||
| end | ||
| def valid_value?(value) | ||
| value.nil? || !!@params[:regex].match(value) | ||
| end | ||
| def params | ||
| @params | ||
| end | ||
| end | ||
| end | ||
| end |
@@ -47,3 +47,3 @@ module Validation | ||
| rescue NameError => e | ||
| raise InvalidRule | ||
| raise InvalidRule.new(e) | ||
| end | ||
@@ -57,15 +57,4 @@ end | ||
| valid = true | ||
| all_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| | ||
| rules.each_pair do |field, rules| | ||
| if ! @obj.respond_to?(field) | ||
@@ -125,2 +114,3 @@ raise InvalidKey | ||
| def initialize(obj) | ||
| @rules = self.class.rules if self.class.is_a?(Validation::Rules) | ||
| @obj = obj | ||
@@ -127,0 +117,0 @@ end |
| module Validation | ||
| VERSION = '0.3.1' | ||
| VERSION = '0.4.0' | ||
| end |
+6
-5
@@ -55,4 +55,4 @@ # Validator | ||
| - `error_key` a symbol to represent the error. This shows up in the errors hash | ||
| - `valid_values?(value)` the beef of the rule. This is where you determine if the value is valid or not | ||
| - `error_key` a symbol to represent the error. This shows up in the errors hash. Must be an underscored_version of the class name | ||
| - `valid_value?(value)` the beef of the rule. This is where you determine if the value is valid or not | ||
| - `params` the params hash that was passed into the constructor | ||
@@ -87,6 +87,7 @@ | ||
| 1. Fork the repository | ||
| 2. Write specs for the change | ||
| 3. Add your change | ||
| 4. Submit a pull request | ||
| 2. Create a branch off of the `develop` branch | ||
| 3. Write specs for the change | ||
| 4. Add your change | ||
| 5. Submit a pull request to merge against the `develop` branch | ||
| Don't change any version files or gemspec files in your change. |