database_validation 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/database_validation/version.rb +1 -1
- data/lib/database_validation.rb +7 -3
- metadata +3 -3
data/lib/database_validation.rb
CHANGED
@@ -13,11 +13,15 @@ module DatabaseValidation
|
|
13
13
|
def self.detect_validations(base)
|
14
14
|
base.columns.each do |field|
|
15
15
|
next if field.name == base.primary_key # don't add validations here
|
16
|
+
|
16
17
|
allow_nil = field.null
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
if field.type == :boolean
|
19
|
+
base.send(:validates_inclusion_of, field.name.to_sym, :in => [true, false]) unless allow_nil
|
20
|
+
else
|
21
|
+
base.send(:validates_presence_of, field.name.to_sym) unless allow_nil
|
22
|
+
end
|
20
23
|
|
24
|
+
next if field.limit.nil?
|
21
25
|
if [:integer, :float].include?(field.type)
|
22
26
|
unsigned = field.sql_type.include?('unsigned')
|
23
27
|
maximum = unsigned ? 2 ** (8 * field.limit) : 2 ** (8 * field.limit) / 2
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Crepezzi
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-27 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|