valle 0.2.3 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2397c0090d814c90a8741d75a8f7f180577cbe3
4
- data.tar.gz: 54a8ea77e0490b1a287368c8ec5a478a355170cf
3
+ metadata.gz: 9cfb09e0752993ed015ff6737ffb430e1c3ec37d
4
+ data.tar.gz: ee3bb21e2c0dddefac91cd8bfdaea011d1c26b7f
5
5
  SHA512:
6
- metadata.gz: eaae640af84fb06801a8558f59b609e4df68b6805a8259272e09afc0d5c5ded123578aa1f044b32fddfdfec09db8de67ae7ce6599fde7449ffdbb8f8f1d768f4
7
- data.tar.gz: 011c1cc4f6a3cf91ffee20cc197a6f4bbec5e034b6efef1dd36c4e1475dcdd8212ea80d3c6d521db9f2296c211852f946de4b27f34b66afbfb2ebd9917c04b73
6
+ metadata.gz: 864f0b25a5c2e7f360dd2fbfa3cd7e86814491a316b4dfea97598524d4aa82f5a9ed97e95f044df9d5524bd91ecd5a0a80ad739d194fd2f479687426313f41c6
7
+ data.tar.gz: a8b91e752476c7d15657122477c327bb2e79030a14f4297ec03ca276e8212b66beff4a0d89784db3ea2366a2428b0cc38770d36309347dbc12fd611c9a2ee5db
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.0.0 / 2014-01-14
2
+
3
+ * attributes option changed to exclude_attributes [Anton Kalyaev]
4
+ * models option changed to exclude_models [Anton Kalyaev]
5
+
1
6
  ## 0.2.3 / 2013-12-16
2
7
 
3
8
  * fixes issue #12 with breaking rake db:migrate:reset [Marcus Geißler]
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 specify what models to take into account by adding the file `config/initializers/valle.rb` containing:
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.models = %w(User, Post)
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 `attributes` configuration 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 `exclude_attributes` configuration option:
67
67
 
68
68
  ```ruby
69
69
  Valle.configure do |config|
70
- config.attributes = {
71
- 'User' => %w(id name) # Model => Array of attributes to validate
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 models option should limit the effect of the Valle to the models specified in the list
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.models = %w(Post)
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 attributes option should allow us to skip some attributes
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.attributes = {
86
- 'User' => %w(id)
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 turned gem on only for certain models,
37
- # we need to check whether the model is in the list.
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[:models].nil? ||
44
- options[:models].is_a?(Array) && options[:models].include?(model_name)
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
- !options[:attributes].has_key?(model_name) ||
59
- options[:attributes][model_name].is_a?(Array) && options[:attributes][model_name].include?(attribute)
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
@@ -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
- models: nil, # selects all AR models by default
12
- attributes: ActiveSupport::HashWithIndifferentAccess.new, # adds validators to all attributes by default
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 models=(collection)
24
- self.options[:models] = collection
22
+ def exclude_models=(collection)
23
+ self.options[:exclude_models] = collection
25
24
  end
26
25
 
27
- def attributes=(mapping)
28
- self.options[:attributes] = mapping
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
@@ -1,3 +1,3 @@
1
1
  module Valle
2
- VERSION = "0.2.3"
2
+ VERSION = "1.0.0"
3
3
  end
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.2.3
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: 2013-12-16 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord