lib/aws/record/validators/numericality.rb in aws-sdk-1.8.5 vs lib/aws/record/validators/numericality.rb in aws-sdk-1.9.0
- old
+ new
@@ -9,15 +9,13 @@
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
-require 'aws/record/validator'
-
module AWS
module Record
-
+
# @private
class NumericalityValidator < Validator
ACCEPTED_OPTIONS = [
:greater_than, :greater_than_or_equal_to,
@@ -25,32 +23,32 @@
:equal_to, :only_integer, :odd, :even,
:message, :allow_nil, :allow_blank, :on, :if, :unless,
]
COMPARISONS = {
- :equal_to => :==,
+ :equal_to => :==,
:greater_than => :>,
:greater_than_or_equal_to => :>=,
- :less_than => :<,
+ :less_than => :<,
:less_than_or_equal_to => :<=,
:even => lambda{|value| value.to_i % 2 == 0 },
:odd => lambda{|value| value.to_i % 2 == 1 },
}
def setup record_class
ensure_exclusive(:odd, :even)
- ensure_exclusive(:equal_to,
+ ensure_exclusive(:equal_to,
[:greater_than, :greater_than_or_equal_to,
:less_than, :less_than_or_equal_to])
ensure_type([TrueClass, FalseClass], :only_integer)
ensure_type(TrueClass, :odd, :even)
- ensure_type([Numeric, Symbol, Proc],
+ ensure_type([Numeric, Symbol, Proc],
:greater_than, :greater_than_or_equal_to,
:less_than, :less_than_or_equal_to,
:equal_to)
end
@@ -76,10 +74,10 @@
unless value
record.errors.add(attribute_name, message_for(error_type))
return
end
-
+
COMPARISONS.each do |option,method|
next unless options.has_key?(option)
requirement = case options[option]