validates_subset 1.0.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ac3e5de7a80d20cdddb2d41527f9228a767cc5f
4
- data.tar.gz: 7fbf538b71f54145550823de261b4ac6fb356b7e
3
+ metadata.gz: 5b8541c955ec99c6f3927a09fe5b529ec4731283
4
+ data.tar.gz: f345e04b8700cc02bab8f7275566994cabf72fec
5
5
  SHA512:
6
- metadata.gz: 4f8b260d9e133cd883f4bede331137c57aa51a68ea7883a026e5c6c5306cc2c822584b6c2d4870cb02f0027f1d6fba8d739025e6ba3592a8effc62751ebf5ccb
7
- data.tar.gz: aec647c12952a02a976d09fd4c84c4c2b6629b66a40db0dd45eea4d74cd23fa6b616b59c8005680ebfb7ce5949893cc5777623a6310739b05f969b4511e753aa
6
+ metadata.gz: 4c9780c06be8db238014e199d8dd1ed70c87cca86e88eaf1fd512ec8cea7c2cc1111c30dc61b53f8d74436a563c8be1fb5eeef1ee6c4c39dd5bfe46305f322ac
7
+ data.tar.gz: b9c6e67b0cd46f8a49d82ecb06f1c119baf54e8ad852d9ba159dd85dbbcdee27498d87e192b96ef0193a33823b7e390920b100f80eb6263a510735be4895ce3f
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  .ruby-*
2
+ *.gem
data/.travis.yml CHANGED
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
- rvm: 2.2.1
2
+ rvm:
3
+ - 1.9.3
4
+ - '2.0'
5
+ - 2.2.1
3
6
  script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activemodel'
4
-
5
- group :test do
6
- gem 'rspec'
7
- gem 'pry'
8
- gem 'guard-rspec'
9
- end
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,57 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ validates_subset (1.0.3)
5
+ activemodel (>= 3.0)
6
+
1
7
  GEM
2
8
  remote: https://rubygems.org/
3
9
  specs:
4
- activemodel (4.2.1)
5
- activesupport (= 4.2.1)
10
+ activemodel (4.2.3)
11
+ activesupport (= 4.2.3)
6
12
  builder (~> 3.1)
7
- activesupport (4.2.1)
13
+ activesupport (4.2.3)
8
14
  i18n (~> 0.7)
9
15
  json (~> 1.7, >= 1.7.7)
10
16
  minitest (~> 5.1)
11
17
  thread_safe (~> 0.3, >= 0.3.4)
12
18
  tzinfo (~> 1.1)
13
19
  builder (3.2.2)
14
- celluloid (0.16.0)
15
- timers (~> 4.0.0)
16
- coderay (1.1.0)
17
20
  diff-lcs (1.2.5)
18
- ffi (1.9.8)
19
- formatador (0.2.5)
20
- guard (2.12.5)
21
- formatador (>= 0.2.4)
22
- listen (~> 2.7)
23
- lumberjack (~> 1.0)
24
- nenv (~> 0.1)
25
- notiffany (~> 0.0)
26
- pry (>= 0.9.12)
27
- shellany (~> 0.0)
28
- thor (>= 0.18.1)
29
- guard-compat (1.2.1)
30
- guard-rspec (4.5.2)
31
- guard (~> 2.1)
32
- guard-compat (~> 1.1)
33
- rspec (>= 2.99.0, < 4.0)
34
- hitimes (1.2.2)
35
21
  i18n (0.7.0)
36
22
  json (1.8.3)
37
- listen (2.10.0)
38
- celluloid (~> 0.16.0)
39
- rb-fsevent (>= 0.9.3)
40
- rb-inotify (>= 0.9)
41
- lumberjack (1.0.9)
42
- method_source (0.8.2)
43
23
  minitest (5.7.0)
44
- nenv (0.2.0)
45
- notiffany (0.0.6)
46
- nenv (~> 0.1)
47
- shellany (~> 0.0)
48
- pry (0.10.1)
49
- coderay (~> 1.1.0)
50
- method_source (~> 0.8.1)
51
- slop (~> 3.4)
52
- rb-fsevent (0.9.5)
53
- rb-inotify (0.9.5)
54
- ffi (>= 0.5.0)
24
+ rake (10.4.2)
55
25
  rspec (3.2.0)
56
26
  rspec-core (~> 3.2.0)
57
27
  rspec-expectations (~> 3.2.0)
@@ -65,12 +35,7 @@ GEM
65
35
  diff-lcs (>= 1.2.0, < 2.0)
66
36
  rspec-support (~> 3.2.0)
67
37
  rspec-support (3.2.2)
68
- shellany (0.0.1)
69
- slop (3.6.0)
70
- thor (0.19.1)
71
38
  thread_safe (0.3.5)
72
- timers (4.0.1)
73
- hitimes
74
39
  tzinfo (1.2.2)
75
40
  thread_safe (~> 0.1)
76
41
 
@@ -78,7 +43,7 @@ PLATFORMS
78
43
  ruby
79
44
 
80
45
  DEPENDENCIES
81
- activemodel
82
- guard-rspec
83
- pry
84
- rspec
46
+ bundler (~> 1.3)
47
+ rake (~> 10.0)
48
+ rspec (~> 3.0)
49
+ validates_subset!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jake Yesbeck
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/arguments.rb CHANGED
@@ -38,7 +38,7 @@ module ValidatesSubset
38
38
  # @subset
39
39
  # return: <Hash>
40
40
  def subset
41
- { :subset => @superset }
41
+ { subset: @superset }
42
42
  end
43
43
  end
44
44
  end
@@ -1,4 +1,9 @@
1
1
  require 'active_model'
2
+ require 'active_support/i18n'
3
+
4
+ I18n.load_path << File.dirname(__FILE__) + '/../locale/en.yml'
5
+ I18n.load_path << File.dirname(__FILE__) + '/../locale/pl.yml'
6
+ I18n.load_path << File.dirname(__FILE__) + '/../locale/sv.yml'
2
7
 
3
8
  require_relative './arguments'
4
9
 
@@ -14,7 +19,7 @@ module ActiveModel
14
19
  options[:superset] = options.delete(:subset)
15
20
 
16
21
  merged_options = {
17
- :message => "is expected to be a subset of #{ options[:superset] } and is not."
22
+ message: :subset
18
23
  }.merge(options)
19
24
 
20
25
  super(merged_options)
@@ -50,7 +55,15 @@ module ActiveModel
50
55
 
51
56
  raise error unless error.nil?
52
57
 
53
- record.errors.add(attribute, options[:message])
58
+ value = record.send(attribute)
59
+
60
+ invalid_value = if value.is_a?(Array)
61
+ value - options[:superset]
62
+ else
63
+ value
64
+ end
65
+
66
+ record.errors.add(attribute, :subset, { subset: options[:superset], invalid_value: invalid_value }.merge(message: options[:message]))
54
67
  end
55
68
 
56
69
  # Helper method to return the base expected error:
data/locale/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ subset: is expected to be a subset of %{subset} and is not.
data/locale/pl.yml ADDED
@@ -0,0 +1,4 @@
1
+ pl:
2
+ errors:
3
+ messages:
4
+ subset: musi być podzbiorem %{subset}.
data/locale/sv.yml ADDED
@@ -0,0 +1,4 @@
1
+ sv:
2
+ errors:
3
+ messages:
4
+ subset: "förväntas vara en delmängd av %{subset}."
@@ -21,7 +21,7 @@ describe 'allow blank' do
21
21
  end
22
22
 
23
23
  context 'value is not a valid subset' do
24
- let(:value) { %i[a b c] }
24
+ let(:value) { [:a, :b, :c] }
25
25
 
26
26
  specify do
27
27
  expect(subject).to_not be_valid
@@ -21,7 +21,7 @@ describe 'allow nil' do
21
21
  end
22
22
 
23
23
  context 'value is not a valid subset' do
24
- let(:value) { %i[a b c] }
24
+ let(:value) { [:a, :b, :c] }
25
25
 
26
26
  specify do
27
27
  expect(subject).to_not be_valid
@@ -22,7 +22,7 @@ describe 'if condition' do
22
22
  end
23
23
 
24
24
  context 'value is not a valid subset' do
25
- let(:value) { %i[a b c] }
25
+ let(:value) { [:a, :b, :c] }
26
26
 
27
27
  specify do
28
28
  expect(subject).to_not be_valid
@@ -20,7 +20,7 @@ describe 'custom messaging' do
20
20
  end
21
21
 
22
22
  context 'value is not a valid subset' do
23
- let(:value) { %i[a b c] }
23
+ let(:value) { [:a, :b, :c] }
24
24
 
25
25
  specify do
26
26
  expect(subject).to_not be_valid
@@ -21,7 +21,7 @@ describe 'multiple validations' do
21
21
  end
22
22
 
23
23
  context 'value is not a valid subset' do
24
- let(:value) { %i[a b c] }
24
+ let(:value) { [:a, :b, :c] }
25
25
 
26
26
  specify do
27
27
  expect(subject).to_not be_valid
@@ -22,7 +22,7 @@ describe 'unless condition' do
22
22
  end
23
23
 
24
24
  context 'value is not a valid subset' do
25
- let(:value) { %i[a b c] }
25
+ let(:value) { [:a, :b, :c] }
26
26
 
27
27
  specify do
28
28
  expect(subject).to be_valid
@@ -58,7 +58,7 @@ describe 'unless condition' do
58
58
  end
59
59
 
60
60
  context 'value is not a valid subset' do
61
- let(:value) { %i[a b c] }
61
+ let(:value) { [:a, :b, :c] }
62
62
 
63
63
  specify do
64
64
  expect(subject).to_not be_valid
@@ -1,6 +1,6 @@
1
1
  lib = File.expand_path('../lib/', __FILE__)
2
2
  $:.unshift lib unless $:.include?(lib)
3
- require_relative './version'
3
+ require './version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'validates_subset'
data/version.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  module ValidatesSubset
2
- VERSION = '1.0.2'.freeze
2
+ MAJOR = 1
3
+ MINOR = 1
4
+ TINY = 0
5
+ VERSION = [MAJOR, MINOR, TINY].join('.').freeze
3
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_subset
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Yesbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-19 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -78,9 +78,13 @@ files:
78
78
  - Gemfile
79
79
  - Gemfile.lock
80
80
  - Guardfile
81
+ - LICENSE.txt
81
82
  - README.md
82
83
  - lib/arguments.rb
83
84
  - lib/validates_subset.rb
85
+ - locale/en.yml
86
+ - locale/pl.yml
87
+ - locale/sv.yml
84
88
  - spec/integration/modifiers/allow_blank_spec.rb
85
89
  - spec/integration/modifiers/allow_nil_spec.rb
86
90
  - spec/integration/modifiers/if_spec.rb