valle 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +5 -5
- data/features/configuration.feature +5 -5
- data/lib/valle.rb +8 -7
- data/lib/valle/configuration.rb +6 -7
- data/lib/valle/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cfb09e0752993ed015ff6737ffb430e1c3ec37d
|
4
|
+
data.tar.gz: ee3bb21e2c0dddefac91cd8bfdaea011d1c26b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864f0b25a5c2e7f360dd2fbfa3cd7e86814491a316b4dfea97598524d4aa82f5a9ed97e95f044df9d5524bd91ecd5a0a80ad739d194fd2f479687426313f41c6
|
7
|
+
data.tar.gz: a8b91e752476c7d15657122477c327bb2e79030a14f4297ec03ca276e8212b66beff4a0d89784db3ea2366a2428b0cc38770d36309347dbc12fd611c9a2ee5db
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -45,11 +45,11 @@ Or install it yourself:
|
|
45
45
|
|
46
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.
|
47
47
|
|
48
|
-
However, you can
|
48
|
+
However, you can skip some of them by adding the file `config/initializers/valle.rb` containing:
|
49
49
|
|
50
50
|
```ruby
|
51
51
|
Valle.configure do |config|
|
52
|
-
config.
|
52
|
+
config.exclude_models = %w(Post)
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
@@ -63,12 +63,12 @@ end
|
|
63
63
|
|
64
64
|
### Disabling Valle on specific attributes
|
65
65
|
|
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 `
|
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 `exclude_attributes` configuration option:
|
67
67
|
|
68
68
|
```ruby
|
69
69
|
Valle.configure do |config|
|
70
|
-
config.
|
71
|
-
'User' => %w(
|
70
|
+
config.exclude_attributes = {
|
71
|
+
'User' => %w(image)
|
72
72
|
}
|
73
73
|
end
|
74
74
|
```
|
@@ -37,13 +37,13 @@ Feature:
|
|
37
37
|
When I successfully run `bundle exec rake test --trace`
|
38
38
|
Then the output should contain "1 tests, 1 assertions, 0 failures, 0 errors"
|
39
39
|
|
40
|
-
Scenario: Using the
|
40
|
+
Scenario: Using the exclude_models option should skip the models specified in the list
|
41
41
|
When I successfully run `bundle exec rails g model Post title:string`
|
42
42
|
And I successfully run `bundle exec rake db:migrate --trace`
|
43
43
|
And I write to "config/initializers/valle.rb" with:
|
44
44
|
"""
|
45
45
|
Valle.configure do |config|
|
46
|
-
config.
|
46
|
+
config.exclude_models = %w(User)
|
47
47
|
end
|
48
48
|
"""
|
49
49
|
And I write to "test/unit/user_test.rb" with:
|
@@ -78,12 +78,12 @@ Feature:
|
|
78
78
|
When I successfully run `bundle exec rake test --trace`
|
79
79
|
Then the output should contain "2 tests, 3 assertions, 0 failures, 0 errors"
|
80
80
|
|
81
|
-
Scenario: Using
|
81
|
+
Scenario: Using exclude_attributes option should allow us to skip some attributes
|
82
82
|
When I write to "config/initializers/valle.rb" with:
|
83
83
|
"""
|
84
84
|
Valle.configure do |config|
|
85
|
-
config.
|
86
|
-
'User' => %w(
|
85
|
+
config.exclude_attributes = {
|
86
|
+
'User' => %w(name)
|
87
87
|
}
|
88
88
|
end
|
89
89
|
"""
|
data/lib/valle.rb
CHANGED
@@ -33,30 +33,31 @@ module Valle
|
|
33
33
|
##
|
34
34
|
# Can we process this model
|
35
35
|
#
|
36
|
-
# If the user
|
37
|
-
# we need to check whether the model is
|
36
|
+
# If the user wants to exclude some models,
|
37
|
+
# we need to check whether the model is on the list.
|
38
38
|
#
|
39
39
|
# @param [String] model_name the model name
|
40
40
|
# @see Valle::Configuration
|
41
41
|
#
|
42
42
|
def can_process_model?(model_name)
|
43
|
-
options[:
|
44
|
-
options[:
|
43
|
+
options[:exclude_models].nil? ||
|
44
|
+
options[:exclude_models].is_a?(Array) && !options[:exclude_models].include?(model_name)
|
45
45
|
end
|
46
46
|
|
47
47
|
##
|
48
48
|
# Can we process this attribute
|
49
49
|
#
|
50
50
|
# If the user wants to skip some attributes, we need to check
|
51
|
-
# whether we should add validators to column or not.
|
51
|
+
# whether we should add validators to that column or not.
|
52
52
|
#
|
53
53
|
# @param [String] model_name model name
|
54
54
|
# @param [String] attribute attribute name
|
55
55
|
# @see Valle::Configuration
|
56
56
|
#
|
57
57
|
def can_process_column?(model_name, attribute)
|
58
|
-
|
59
|
-
options[:
|
58
|
+
options[:exclude_attributes].nil? ||
|
59
|
+
!options[:exclude_attributes].has_key?(model_name) ||
|
60
|
+
options[:exclude_attributes][model_name].is_a?(Array) && !options[:exclude_attributes][model_name].include?(attribute)
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
data/lib/valle/configuration.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
-
require 'active_support/hash_with_indifferent_access'
|
3
2
|
|
4
3
|
module Valle
|
5
4
|
module Configuration
|
@@ -8,8 +7,8 @@ module Valle
|
|
8
7
|
|
9
8
|
self.options = {
|
10
9
|
enabled: true, # gem is enabled by default
|
11
|
-
|
12
|
-
|
10
|
+
exclude_models: nil, # selects all AR models by default
|
11
|
+
exclude_attributes: nil, # adds validators to all attributes by default
|
13
12
|
}
|
14
13
|
|
15
14
|
def configure
|
@@ -20,12 +19,12 @@ module Valle
|
|
20
19
|
self.options[:enabled] = value
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
self.options[:
|
22
|
+
def exclude_models=(collection)
|
23
|
+
self.options[:exclude_models] = collection
|
25
24
|
end
|
26
25
|
|
27
|
-
def
|
28
|
-
self.options[:
|
26
|
+
def exclude_attributes=(mapping)
|
27
|
+
self.options[:exclude_attributes] = mapping
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
data/lib/valle/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Kalyaev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|