database_validations 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4817334b7a4a7ae57f43e69be04b5969dbb35dcbb39f4bd2ebc52603cf149a15
|
4
|
+
data.tar.gz: b899b604b2f72021269c39372c60acf0fb4a6805e4d3e2b5f606320aa165bb9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2b50fd0375c72c71ce1a443131a3c16f84118153947a373280ee9b28f6d6572abf3576acbf4be0660e3d436f30abce62d0072c2297c47e557dc894c002ceb74
|
7
|
+
data.tar.gz: 53e6a6363cc2d64763e9ba3c6089911dc09950c799ffcdbfd51f7d792e48c04f82cb8fc47435b01fad64567ba7ba625c865788ccaf73e79a3745e734f752fed9
|
data/README.md
CHANGED
@@ -39,8 +39,7 @@ Disadvantages:
|
|
39
39
|
- Cannot handle multiple validations at once because database raises only one error for all indexes per query.
|
40
40
|
```ruby
|
41
41
|
class User < ActiveRecord::Base
|
42
|
-
validates_db_uniqueness_of :email
|
43
|
-
validates_db_uniqueness_of :name
|
42
|
+
validates_db_uniqueness_of :email, :name
|
44
43
|
end
|
45
44
|
|
46
45
|
original = User.create(name: 'name', email: 'email@mail.com')
|
@@ -82,10 +81,10 @@ List of supported options from `validates_uniqueness_of` validator:
|
|
82
81
|
- `scope`: One or more columns by which to limit the scope of the uniqueness constraint.
|
83
82
|
- `message`: Specifies a custom error message (default is: "has already been taken").
|
84
83
|
- `if`: Specifies a method or proc to call to determine if the validation should occur
|
85
|
-
(e.g.
|
84
|
+
(e.g. `if: :allow_validation`, or `if: Proc.new { |user| user.signup_step > 2 }`). The method or
|
86
85
|
proc should return or evaluate to a `true` or `false` value.
|
87
86
|
- `unless`: Specifies a method or proc to call to determine if the validation should not
|
88
|
-
occur (e.g.
|
87
|
+
occur (e.g. `unless: :skip_validation`, or `unless: Proc.new { |user| user.signup_step <= 2 }`).
|
89
88
|
The method or proc should return or evaluate to a `true` or `false` value.
|
90
89
|
|
91
90
|
**Keep in mind**: Both `if` and `unless` options are used only for `valid?` method and provided only for performance reason.
|
@@ -115,10 +114,10 @@ validates_uniqueness_of :email, allow_nil: true, allow_blank: false, case_sensit
|
|
115
114
|
|
116
115
|
List of supported options for `PostgreSQL` only:
|
117
116
|
|
118
|
-
- `where`: Specify the conditions to be included as a
|
119
|
-
limit the uniqueness constraint lookup (e.g.
|
117
|
+
- `where`: Specify the conditions to be included as a `WHERE` SQL fragment to
|
118
|
+
limit the uniqueness constraint lookup (e.g. `where: "(status = 'active')"`).
|
120
119
|
For backward compatibility, this will be converted automatically
|
121
|
-
to
|
120
|
+
to `conditions: -> { where("(status = 'active')") }` for `valid?` method.
|
122
121
|
|
123
122
|
The list of options to add support:
|
124
123
|
|
@@ -8,7 +8,7 @@ module DatabaseValidations
|
|
8
8
|
module_function
|
9
9
|
|
10
10
|
def factory(model)
|
11
|
-
case (database = model.
|
11
|
+
case (database = model.connection_config[:adapter].downcase.to_sym)
|
12
12
|
when SqliteAdapter::ADAPTER then SqliteAdapter.new(model)
|
13
13
|
when PostgresqlAdapter::ADAPTER then PostgresqlAdapter.new(model)
|
14
14
|
when MysqlAdapter::ADAPTER then MysqlAdapter.new(model)
|
@@ -2,7 +2,7 @@ module DatabaseValidations
|
|
2
2
|
module Adapters
|
3
3
|
class SqliteAdapter < BaseAdapter
|
4
4
|
SUPPORTED_OPTIONS = %i[scope message if unless].freeze
|
5
|
-
ADAPTER = :
|
5
|
+
ADAPTER = :sqlite3
|
6
6
|
|
7
7
|
def error_columns(error_message)
|
8
8
|
error_message.scan(/#{model.table_name}\.([^,:]+)/).flatten
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|