schema_validations 1.0.1 → 1.1.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +4 -1
- data/README.md +20 -12
- data/gemfiles/Gemfile.base +3 -1
- data/gemfiles/rails-3.2/Gemfile.sqlite3 +10 -0
- data/gemfiles/rails-4.1/Gemfile.sqlite3 +10 -0
- data/gemfiles/rails-4.2/Gemfile.base +3 -0
- data/gemfiles/rails-4.2/Gemfile.sqlite3 +10 -0
- data/lib/schema_validations/active_record/validations.rb +17 -22
- data/lib/schema_validations/version.rb +1 -1
- data/schema_dev.yml +2 -1
- data/schema_validations.gemspec +1 -1
- data/spec/schema_validations.sqlite3 +0 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a393a0d55876bd8f8e7564c4697d49e39192a253
|
4
|
+
data.tar.gz: da40a15493d7ee658427ad9b8fa84d55b18cf1c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46e9332822a7060a8815c85607a5879299b69626ceffa5cf5702d28272557f62341ae0e6af197841bbf398e985c8726d0eac7d5a7645adeaf75658d7d28e5644
|
7
|
+
data.tar.gz: ff590cab2b092c7cc5cdfb75bfe0a5acfc5235a6e8ef787a807550cc1b1fb2072d804447bedbe67df08cd2c2005ba316e18278fa0e8d8adc7a2dbc83fbc9c974
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -3,9 +3,12 @@
|
|
3
3
|
# Please do not edit this file; any changes will be overwritten next time
|
4
4
|
# schema_dev gets run.
|
5
5
|
---
|
6
|
+
sudo: false
|
6
7
|
rvm:
|
7
8
|
- 1.9.3
|
8
|
-
- 2.1.
|
9
|
+
- 2.1.5
|
9
10
|
gemfile:
|
10
11
|
- gemfiles/rails-3.2/Gemfile.sqlite3
|
11
12
|
- gemfiles/rails-4.1/Gemfile.sqlite3
|
13
|
+
- gemfiles/rails-4.2/Gemfile.sqlite3
|
14
|
+
script: bundle exec rake travis
|
data/README.md
CHANGED
@@ -4,9 +4,11 @@ SchemaValidations is an ActiveRecord extension that keeps your model class
|
|
4
4
|
definitions simpler and more DRY, by automatically defining validations based
|
5
5
|
on the database schema.
|
6
6
|
|
7
|
-
[](http://badge.fury.io/rb/schema_validations)
|
8
|
+
[](http://travis-ci.org/SchemaPlus/schema_validations)
|
9
|
+
[](https://coveralls.io/r/SchemaPlus/schema_validations)
|
10
|
+
[](https://gemnasium.com/lomba/schema_validations)
|
11
|
+
|
10
12
|
|
11
13
|
## Overview
|
12
14
|
|
@@ -41,11 +43,19 @@ installing it your model is as simple as it can be.
|
|
41
43
|
Validations are there but they are created by schema_validations under the
|
42
44
|
hood.
|
43
45
|
|
46
|
+
## Compatibility
|
47
|
+
|
48
|
+
SchemaValidations is tested on all combinations of:
|
49
|
+
|
50
|
+
* rails 3.2, 4.1, and 4.2
|
51
|
+
* MRI ruby 1.9.3 and 2.1.5)'s
|
52
|
+
config.
|
53
|
+
|
44
54
|
## Installation
|
45
55
|
|
46
56
|
Simply add schema_validations to your Gemfile.
|
47
57
|
|
48
|
-
gem "schema_validations"
|
58
|
+
gem "schema_validations"
|
49
59
|
|
50
60
|
### What if I want something special?
|
51
61
|
|
@@ -100,15 +110,9 @@ Data types:
|
|
100
110
|
SchemaValidations uses the [schema_plus](http://rubygems.org/gems/schema_plus)
|
101
111
|
gem for its schema queries. That gem will by default auto-create foreign key
|
102
112
|
constraints that you probably want -- but if you don't want them, you can
|
103
|
-
disable them using [schema_plus](http://rubygems.org/gems/schema_plus
|
104
|
-
config.
|
105
|
-
|
106
|
-
## Compatibility
|
113
|
+
disable them using [schema_plus](http://rubygems.org/gems/schema_plus
|
107
114
|
|
108
|
-
SchemaValidations is tested on all combinations of:
|
109
115
|
|
110
|
-
* rails 3.2 or 4.1
|
111
|
-
* MRI ruby 1.9.3 and 2.1.3
|
112
116
|
|
113
117
|
## How do I know what it did?
|
114
118
|
If you're curious (or dubious) about what validations SchemaValidations
|
@@ -129,9 +133,13 @@ use case.
|
|
129
133
|
|
130
134
|
## Release Notes
|
131
135
|
|
136
|
+
### 1.1.0
|
137
|
+
|
138
|
+
* Works with Rails 4.2.
|
139
|
+
|
132
140
|
### 1.0.1
|
133
141
|
|
134
|
-
* Fix enums in Rails 4.1. [@lowjoel](https://github.com/lowjoel)
|
142
|
+
* Fix enums in Rails 4.1. Thanks to [@lowjoel](https://github.com/lowjoel)
|
135
143
|
|
136
144
|
### 1.0.0
|
137
145
|
|
data/gemfiles/Gemfile.base
CHANGED
@@ -96,17 +96,27 @@ module SchemaValidations
|
|
96
96
|
name = column.name.to_sym
|
97
97
|
|
98
98
|
# Data-type validation
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
99
|
+
datatype = case
|
100
|
+
when respond_to?(:defined_enums) && defined_enums.has_key?(column.name) then :enum
|
101
|
+
when column.type == :integer then :integer
|
102
|
+
when column.number? then :numeric
|
103
|
+
when column.respond_to?(:text?) && column.text? then :text
|
104
|
+
when [:string, :text].include?(column.type) then :text
|
105
|
+
when column.type == :boolean then :boolean
|
106
|
+
end
|
107
|
+
|
108
|
+
case datatype
|
109
|
+
when :integer
|
110
|
+
validate_logged :validates_numericality_of, name, :allow_nil => true, :only_integer => true
|
111
|
+
when :numeric
|
112
|
+
validate_logged :validates_numericality_of, name, :allow_nil => true
|
113
|
+
when :text
|
114
|
+
validate_logged :validates_length_of, name, :allow_nil => true, :maximum => column.limit if column.limit
|
105
115
|
end
|
106
116
|
|
107
117
|
# NOT NULL constraints
|
108
118
|
if column.required_on
|
109
|
-
if
|
119
|
+
if datatype == :boolean
|
110
120
|
validate_logged :validates_inclusion_of, name, :in => [true, false], :message => :blank
|
111
121
|
else
|
112
122
|
validate_logged :validates_presence_of, name
|
@@ -118,21 +128,6 @@ module SchemaValidations
|
|
118
128
|
end
|
119
129
|
end
|
120
130
|
|
121
|
-
def load_integer_column_validations(name, column)
|
122
|
-
is_enum_column = respond_to?(:defined_enums) && defined_enums.has_key?(column.name)
|
123
|
-
unless is_enum_column
|
124
|
-
validate_logged :validates_numericality_of, name, :allow_nil => true, :only_integer => true
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def load_numeric_column_validations(name, _)
|
129
|
-
validate_logged :validates_numericality_of, name, :allow_nil => true
|
130
|
-
end
|
131
|
-
|
132
|
-
def load_string_column_validations(name, column)
|
133
|
-
validate_logged :validates_length_of, name, :allow_nil => true, :maximum => column.limit
|
134
|
-
end
|
135
|
-
|
136
131
|
def load_association_validations #:nodoc:
|
137
132
|
reflect_on_all_associations(:belongs_to).each do |association|
|
138
133
|
# :primary_key_name was deprecated (noisily) in rails 3.1
|
data/schema_dev.yml
CHANGED
data/schema_validations.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.add_dependency("schema_plus")
|
24
24
|
|
25
|
-
s.add_development_dependency("schema_dev", "~> 1.
|
25
|
+
s.add_development_dependency("schema_dev", "~> 1.2")
|
26
26
|
s.add_development_dependency("rake")
|
27
27
|
s.add_development_dependency("rdoc")
|
28
28
|
s.add_development_dependency("rspec")
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: schema_plus
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '1.
|
34
|
+
version: '1.2'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
41
|
+
version: '1.2'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +142,11 @@ files:
|
|
142
142
|
- Rakefile
|
143
143
|
- gemfiles/Gemfile.base
|
144
144
|
- gemfiles/rails-3.2/Gemfile.base
|
145
|
+
- gemfiles/rails-3.2/Gemfile.sqlite3
|
145
146
|
- gemfiles/rails-4.1/Gemfile.base
|
147
|
+
- gemfiles/rails-4.1/Gemfile.sqlite3
|
148
|
+
- gemfiles/rails-4.2/Gemfile.base
|
149
|
+
- gemfiles/rails-4.2/Gemfile.sqlite3
|
146
150
|
- init.rb
|
147
151
|
- lib/schema_validations.rb
|
148
152
|
- lib/schema_validations/active_record/validations.rb
|
@@ -150,6 +154,7 @@ files:
|
|
150
154
|
- lib/schema_validations/version.rb
|
151
155
|
- schema_dev.yml
|
152
156
|
- schema_validations.gemspec
|
157
|
+
- spec/schema_validations.sqlite3
|
153
158
|
- spec/spec_helper.rb
|
154
159
|
- spec/support/active_model.rb
|
155
160
|
- spec/validations_spec.rb
|
@@ -178,6 +183,7 @@ signing_key:
|
|
178
183
|
specification_version: 4
|
179
184
|
summary: Automatically creates validations basing on the database schema.
|
180
185
|
test_files:
|
186
|
+
- spec/schema_validations.sqlite3
|
181
187
|
- spec/spec_helper.rb
|
182
188
|
- spec/support/active_model.rb
|
183
189
|
- spec/validations_spec.rb
|