roqua-support 0.1.19 → 0.1.20

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
  SHA1:
3
- metadata.gz: 54d706d399e594e9134c31f0fe79b7411bc9feb6
4
- data.tar.gz: b7b0e7cf40671cc9bd9a24a266e55dd2cc342318
3
+ metadata.gz: 4e8bd876218d378c21add709e9625782de687197
4
+ data.tar.gz: 8edb8923293e61035707854c43f3b04b937359ac
5
5
  SHA512:
6
- metadata.gz: 0a3a19acaff5ebfbd26431073f5cf83f0abb332a93628cc98d85190e54ecede61da2939c140d6acdf318e18a583448bad36b9f33b4dc817e4e7caace7c9d3105
7
- data.tar.gz: 5a1fd2afb46ca30fea972a4d0f6dc16812ac736137e42db9c77318c86d18050c0d9b9a65ecb3c6db075cd8993c8c7b66d24e3b634cecbf7d2142e11f97bf1d2c
6
+ metadata.gz: f46cd09d06f2b1d094c4de58dba69d3e0d5bf632390b6190d0f7694ee975500c0bb70f7d420fddc7d295ac68d4a0dc032e45821a26490b0580be98cd8205f0ac
7
+ data.tar.gz: 3f1b4ddf2053b3d7fe7d7e7e92b21f3b7f52cd141e5c0b9a8250b15803a1e1ed6f1d88ab414746b614b1e7a1c5d673795535bc7114416c27d537c1d56d80f872
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.20
2
+
3
+ * Add SubsetValidator
4
+
1
5
  ## 0.1.19
2
6
 
3
7
  * Add active_interaction/rails_instrumentation
data/README.md CHANGED
@@ -103,6 +103,22 @@ DurationFilterOperation.run(duration: {value: 1, unit: 'weeks'})
103
103
  Allows you to specify an ActiveSupport::Duration attribute.
104
104
 
105
105
 
106
+ ### Validators
107
+
108
+ ```ruby
109
+ require 'roqua/validators/subset_validator'
110
+ ```
111
+
112
+ In errors.yml (Optional - Given defaults are available)
113
+ ```
114
+ nl:
115
+ errors:
116
+ messages:
117
+ subset: bevat onbekende keuzes
118
+ ```
119
+
120
+
121
+
106
122
  ## Contributing
107
123
 
108
124
  1. Fork it
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module Support
3
- VERSION = '0.1.19'
3
+ VERSION = '0.1.20'
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ I18n.backend.store_translations :nl, errors: {
2
+ messages: { subset: 'bevat onbekende keuzes' }
3
+ }
4
+
5
+ class SubsetValidator < ActiveModel::EachValidator
6
+ def validate_each(record, attribute, value)
7
+ return unless value
8
+ unless value.all? { |element| options.fetch(:of).include? element }
9
+ record.errors[attribute] << (options[:message] || I18n.t('errors.messages.subset'))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'roqua/validators/subset_validator'
3
+
4
+ describe SubsetValidator do
5
+ let(:validatable) do
6
+ Class.new do
7
+ include ActiveModel::Validations
8
+
9
+ attr_accessor :list
10
+
11
+ validates :list, subset: {of: [1, 2, 3]}
12
+
13
+ def initialize(list)
14
+ self.list = list
15
+ end
16
+ end
17
+ end
18
+
19
+ it 'allows nil values' do
20
+ expect(validatable.new(nil)).to be_valid
21
+ end
22
+
23
+ it 'allows empty arrays' do
24
+ expect(validatable.new([])).to be_valid
25
+ end
26
+
27
+ it 'allows a subset' do
28
+ expect(validatable.new([1])).to be_valid
29
+ expect(validatable.new([1, 2])).to be_valid
30
+ end
31
+
32
+ it 'allows exact match to set' do
33
+ expect(validatable.new([1, 2, 3])).to be_valid
34
+ end
35
+
36
+ it 'does not allow an element not in the set' do
37
+ expect(validatable.new([1, 2, 100])).not_to be_valid
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,6 +129,7 @@ files:
129
129
  - lib/roqua/support/request_logger.rb
130
130
  - lib/roqua/support/stats.rb
131
131
  - lib/roqua/support/stats/hosted_graphite_backend.rb
132
+ - lib/roqua/validators/subset_validator.rb
132
133
  - roqua-support.gemspec
133
134
  - spec/roqua/core_ext/active_interaction/date_time_as_unix_extension_spec.rb
134
135
  - spec/roqua/core_ext/active_interaction/duration_filter_spec.rb
@@ -146,6 +147,7 @@ files:
146
147
  - spec/roqua/support/request_logger_spec.rb
147
148
  - spec/roqua/support/stats_spec.rb
148
149
  - spec/roqua/support_spec.rb
150
+ - spec/roqua/validators/subset_validator_spec.rb
149
151
  - spec/spec_helper.rb
150
152
  homepage: https://github.com/roqua/roqua-support
151
153
  licenses:
@@ -188,5 +190,6 @@ test_files:
188
190
  - spec/roqua/support/request_logger_spec.rb
189
191
  - spec/roqua/support/stats_spec.rb
190
192
  - spec/roqua/support_spec.rb
193
+ - spec/roqua/validators/subset_validator_spec.rb
191
194
  - spec/spec_helper.rb
192
195
  has_rdoc: