rao-or_validator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '068c98eea996fada959fa9d89b6dc7efff5446bdf251e6a7dbba5558fc82c6f4'
4
+ data.tar.gz: d7e725a97bcdad560f0157815984b4cb4bbbf88f3830c37848ce7ae969ebd60c
5
+ SHA512:
6
+ metadata.gz: 89488e3dd6a21518f93876301d468ee41e60e31acb95166fc6856653c6a1fbbca647cf6a6c85dc35d7a157362d4644b458d89e4ea8d5c5d4d6bc4569ba031ab6
7
+ data.tar.gz: cd2e21a587e9fe9f5d8101c0717f2b18793c523629a986b55a97159d92b2fe87d15192726a0b70b22db885ad843bfce481032efb126e373f3198096600342a5b
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Roberto Vasquez Angel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ # x(or) validator for rails
@@ -0,0 +1,8 @@
1
+ de:
2
+ activerecord:
3
+ errors:
4
+ messages:
5
+ or:
6
+ default: "Mindestens eins der folgenden Felder muss ausgefüllt sein: %{attribute_names}."
7
+ exclusive: "Nur eins der folgenden Felder darf ausgefüllt sein: %{attribute_names}."
8
+
@@ -0,0 +1,8 @@
1
+ en:
2
+ activerecord:
3
+ errors:
4
+ messages:
5
+ or:
6
+ default: "at least one of #{attribute_names} must be present."
7
+ exclusive: "exactly one of %{attribute_names} may be present."
8
+
@@ -0,0 +1,20 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class OrValidator < ::ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ values = options[:others].map{ |o| record.send(o) } + [value]
6
+ attribute_names = ([attribute] + options[:others]).map { |attr_name| record.class.human_attribute_name(attr_name) }
7
+
8
+ if options[:exclusive]
9
+ if values.count { |x| x.present? } != 1
10
+ record.errors.add(attribute, options[:message] || I18n.t('activerecord.errors.messages.or.exclusive', attribute_names: attribute_names.to_sentence))
11
+ end
12
+ else
13
+ if values.all? { |x| x.blank? }
14
+ record.errors.add(attribute, options[:message] || I18n.t('activerecord.errors.messages.or.default', attribute_names: attribute_names.to_sentence))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'rao/or_validator/engine'
2
+ require 'rao/or_validator/version'
3
+ require 'active_model/validations/or_validator'
4
+
5
+ module Rao
6
+ module OrValidator
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Rao
2
+ module OrValidator
3
+ class Engine < Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Rao
2
+ module OrValidator
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rao-or_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Vasquez Angel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Provides an (x)or validator for active model.
28
+ email:
29
+ - roberto@vasquez-angel.de
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - config/locales/or_validator.de.yml
37
+ - config/locales/or_validator.en.yml
38
+ - lib/active_model/validations/or_validator.rb
39
+ - lib/rao-or_validator.rb
40
+ - lib/rao/or_validator/engine.rb
41
+ - lib/rao/or_validator/version.rb
42
+ homepage: https://github.com/robotex82/rao-or_validator
43
+ licenses: []
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.0.6
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Provides an (x)or validator for active model.
64
+ test_files: []