valle 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +31 -33
- data/lib/valle/abstract_adapter/byte_limited_column.rb +2 -1
- data/lib/valle/abstract_adapter/column_wrapper.rb +0 -1
- data/lib/valle/hooks.rb +1 -1
- data/lib/valle/version.rb +1 -1
- metadata +11 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf514cc9b79f38e7ee4b7d7caeb9a13abf294f47
|
4
|
+
data.tar.gz: fb3630e3ff30d01fff6a43d1f8916ecb5cca1578
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0a37000da3fe826b10496dc335ad14d0e6a97bde094616f86da813e4449e621449dd4be98afaf29a9be4ba2cc401dde6b7b3d9138c1200c8bf263bad52449e8
|
7
|
+
data.tar.gz: fc6909f682a8a68513eb3a8fda035d57ffc7a9449d41ef878b79ef98c57d0ddd8baccd9246e7c81026e0dc691820434e6602fdec47a69becc8fbb8430ce05bda
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
# Valle [![Build Status](https://secure.travis-ci.org/kaize/valle.png "Build Status")](http://travis-ci.org/kaize/valle) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kaize/valle)
|
2
2
|
|
3
|
-
Valle automatically
|
4
|
-
ActiveRecord model(s), so you shouldn't worry, that string length or ID
|
5
|
-
value will exceed the permissible DB limit for this type of field.
|
3
|
+
Valle automatically creates validations for the minimum and maximum values of fields in your ActiveRecord model(s). No more worrying that string lengths or ID values will exceed the permissible DB limits!
|
6
4
|
|
7
|
-
For example, maximum length of the string in PostgreSQL is 255.
|
8
|
-
setup the following validator for you, so you don't need to write it by
|
9
|
-
hands.
|
5
|
+
For example, the maximum length of the `string` type in PostgreSQL is 255. Valle creates the following validator for you, so you no longer need to write it by hand:
|
10
6
|
|
11
|
-
|
7
|
+
```ruby
|
8
|
+
validates :field_name, length: { maximum: 255 }
|
9
|
+
```
|
12
10
|
|
13
|
-
Note: If you do not do this (and usually you are) and try to enter 2147483648 into
|
11
|
+
Note: If you do not do this (and usually you are) and try to enter 2147483648 into a field of type `integer` (see the [Numeric types](http://www.postgresql.org/docs/9.2/static/datatype-numeric.html) section of PostgreSQL docs), you will get a 500 error.
|
14
12
|
|
15
13
|
Example:
|
16
14
|
|
17
15
|
PG::Error: ERROR: value "2147483648" is out of range for type integer
|
18
16
|
: SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1
|
19
17
|
|
20
|
-
###
|
18
|
+
### Rails versions currently supported
|
21
19
|
|
22
20
|
- 3.x
|
23
21
|
- 4.x
|
@@ -39,45 +37,45 @@ And then execute:
|
|
39
37
|
|
40
38
|
$ bundle
|
41
39
|
|
42
|
-
Or install it yourself
|
40
|
+
Or install it yourself:
|
43
41
|
|
44
42
|
$ gem install valle
|
45
43
|
|
46
44
|
## Usage
|
47
45
|
|
48
|
-
By default, this gem adds validators to all your ActiveRecord models.
|
49
|
-
This means that, basically, you don't need to tweak it.
|
46
|
+
By default, this gem adds validators to all your ActiveRecord models. If that is the behavior you want, you don't need to tweak it.
|
50
47
|
|
51
|
-
However, you
|
48
|
+
However, you can specify what models to take into account by adding the file `config/initializers/valle.rb` containing:
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
```ruby
|
51
|
+
Valle.configure do |config|
|
52
|
+
config.models = %w(User, Post)
|
53
|
+
end
|
54
|
+
```
|
56
55
|
|
57
|
-
Also, you
|
56
|
+
Also, you can disable it temporarily by setting the `enabled` configuration option to `false`.
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
```ruby
|
59
|
+
Valle.configure do |config|
|
60
|
+
config.enabled = false
|
61
|
+
end
|
62
|
+
```
|
62
63
|
|
63
|
-
### Disabling
|
64
|
+
### Disabling Valle on specific attributes
|
64
65
|
|
65
|
-
There are cases where you need to skip validation for a particular
|
66
|
-
attribute (see [#4](https://github.com/kaize/valle/issues/4)). For
|
67
|
-
example, CarrierWave stores his images temporarily in attributes, so calling
|
68
|
-
`save` on them will fail because of LengthValidator (255 chars maximum).
|
69
|
-
You can disable this gem for such fields using `attributes` option.
|
66
|
+
There are cases where you need to skip validation for a particular attribute (see [#4](https://github.com/kaize/valle/issues/4)). For example, *CarrierWave* stores images temporarily in attributes, so calling `save` on them will fail because of its LengthValidator (255 characters maximum). You can disable Valle for such fields using the `attributes` configuration option:
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
```ruby
|
69
|
+
Valle.configure do |config|
|
70
|
+
config.attributes = {
|
71
|
+
'User' => %w(id name) # Model => Array of attributes to validate
|
72
|
+
}
|
73
|
+
end
|
74
|
+
```
|
76
75
|
|
77
76
|
## Alternatives
|
78
77
|
|
79
|
-
There is a similar gem, called [validates_lengths_from_database](http://github.com/rubiety/validates_lengths_from_database). It solves only one part
|
80
|
-
applicable to strings. This gem is designed to work with all possible field types.
|
78
|
+
There is a similar gem, called [validates_lengths_from_database](http://github.com/rubiety/validates_lengths_from_database). It solves only one part of the problem — applicable to strings. Valle, however, is designed to work with all possible field types.
|
81
79
|
|
82
80
|
## Contributing
|
83
81
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Valle
|
2
2
|
module AbstractAdapter
|
3
3
|
class ByteLimitedColumn < AbstractColumn
|
4
|
-
|
5
4
|
def maximum
|
6
5
|
case limit
|
7
6
|
when 1; 127
|
8
7
|
when 2; 32767
|
9
8
|
when 3; 8388607
|
10
9
|
when 4; 2147483647
|
10
|
+
when 6; 140737488355327
|
11
11
|
when 8; 9223372036854775807
|
12
12
|
end
|
13
13
|
end
|
@@ -18,6 +18,7 @@ module Valle
|
|
18
18
|
when 2; -32768
|
19
19
|
when 3; -8388608
|
20
20
|
when 4; -2147483648
|
21
|
+
when 6; -140737488355328
|
21
22
|
when 8; -9223372036854775808
|
22
23
|
end
|
23
24
|
end
|
data/lib/valle/hooks.rb
CHANGED
@@ -22,7 +22,7 @@ module Valle
|
|
22
22
|
inherited_without_valle_validators(subclass)
|
23
23
|
if (Valle.can_process_model?(subclass.model_name) &&
|
24
24
|
self == ActiveRecord::Base &&
|
25
|
-
subclass != ActiveRecord::SchemaMigration)
|
25
|
+
(defined?(ActiveRecord::SchemaMigration) && subclass != ActiveRecord::SchemaMigration)) # skip AR::SchemaMigration (AR >= 4.X)
|
26
26
|
Valle::Hooks.extend_ar_validations_valid_method(subclass)
|
27
27
|
end
|
28
28
|
end
|
data/lib/valle/version.rb
CHANGED
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Anton Kalyaev
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activesupport
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Valle automatically sets minimum and maximum values for the fields of
|
@@ -82,33 +77,26 @@ files:
|
|
82
77
|
homepage: http://github.com/kaize/valle
|
83
78
|
licenses:
|
84
79
|
- MIT
|
80
|
+
metadata: {}
|
85
81
|
post_install_message:
|
86
82
|
rdoc_options: []
|
87
83
|
require_paths:
|
88
84
|
- lib
|
89
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
86
|
requirements:
|
92
|
-
- -
|
87
|
+
- - '>='
|
93
88
|
- !ruby/object:Gem::Version
|
94
89
|
version: '0'
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
hash: 1784568943326759879
|
98
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
91
|
requirements:
|
101
|
-
- -
|
92
|
+
- - '>='
|
102
93
|
- !ruby/object:Gem::Version
|
103
94
|
version: '0'
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
hash: 1784568943326759879
|
107
95
|
requirements: []
|
108
96
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
97
|
+
rubygems_version: 2.1.11
|
110
98
|
signing_key:
|
111
|
-
specification_version:
|
99
|
+
specification_version: 4
|
112
100
|
summary: Built-in limit validations for your ActiveRecord model.
|
113
101
|
test_files:
|
114
102
|
- features/configuration.feature
|