sexy_validations 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/sexy_validations/validators/age.rb +12 -8
- data/lib/sexy_validations/validators/date.rb +27 -0
- data/sexy_validations.gemspec +2 -1
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -11,15 +11,19 @@ module SexyValidations
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
if value.is_a?(::Date)
|
15
|
+
min = options[:within].min
|
16
|
+
if value.calc_age < min
|
17
|
+
record.errors.add(attribute, "zu jung (mindestes #{min} Jahre)")
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
max = options[:within].max
|
21
|
+
if value.calc_age > max
|
22
|
+
record.errors.add(attribute, "zu alt (maximal #{max} Jahre)")
|
23
|
+
end
|
24
|
+
else
|
25
|
+
record.errors.add(attribute, "ungültig")
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module SexyValidations
|
3
|
+
module Validators
|
4
|
+
class Date
|
5
|
+
def self.validate(record, attribute, value, options)
|
6
|
+
return unless value
|
7
|
+
|
8
|
+
if value.is_a?(::Date)
|
9
|
+
if options.is_a?(Hash)
|
10
|
+
min = options[:within].min
|
11
|
+
if value < min
|
12
|
+
record.errors.add(attribute, "zu früh (frühestens #{min})")
|
13
|
+
end
|
14
|
+
|
15
|
+
max = options[:within].max
|
16
|
+
if value > max
|
17
|
+
record.errors.add(attribute, "zu spät (spätestens #{max})")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
else
|
21
|
+
record.errors.add(attribute, "ungültig")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
data/sexy_validations.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sexy_validations}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corin Langosch"]
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/sexy_validations/validators/age.rb",
|
30
30
|
"lib/sexy_validations/validators/confirmation.rb",
|
31
31
|
"lib/sexy_validations/validators/count.rb",
|
32
|
+
"lib/sexy_validations/validators/date.rb",
|
32
33
|
"lib/sexy_validations/validators/email.rb",
|
33
34
|
"lib/sexy_validations/validators/file.rb",
|
34
35
|
"lib/sexy_validations/validators/format.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Corin Langosch
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/sexy_validations/validators/age.rb
|
55
55
|
- lib/sexy_validations/validators/confirmation.rb
|
56
56
|
- lib/sexy_validations/validators/count.rb
|
57
|
+
- lib/sexy_validations/validators/date.rb
|
57
58
|
- lib/sexy_validations/validators/email.rb
|
58
59
|
- lib/sexy_validations/validators/file.rb
|
59
60
|
- lib/sexy_validations/validators/format.rb
|