mongoid_localized_presence_validator 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: beacd7442165060e6eeb2cd6df71a2468b40f9752df93464f40140e9caeb87dc
4
+ data.tar.gz: a4e2efb4cb05cc6fbcfa5edf7a8906a37c9506bc0c9e57c64b9730d9b05a7047
5
+ SHA512:
6
+ metadata.gz: 287713a36a0b27cb01c7711ae1d41351629cc7e0d6b6c8efcb06c993847125cef5de93ba5e0956113785497afeaec28445f2e63e1ebfd55a4a64e3f0b02b6f47
7
+ data.tar.gz: 4fd8943586b886b74dcf87e6d2335ae0b34ed93926c481bffcc36562074a7ff05ece5b12d127ea8a5a08b6fcc3bdd423e69c9a6e35ad2c318feed4081cebaf2b
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .DS_Store
11
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ sudo: false
2
+ language: ruby
3
+ script: 'bundle exec rake'
4
+ rvm:
5
+ - 2.5.1
6
+ services:
7
+ - mongodb
8
+ before_install:
9
+ - gem install bundler -v 1.16.1
10
+ notifications:
11
+ email:
12
+ recipients:
13
+ - tomas.celizna@gmail.com
14
+ - a@asgerbehnckejacobsen.dk
15
+ on_failure: change
16
+ on_success: never
17
+
18
+ matrix:
19
+ include:
20
+ - rvm: 2.3.3
21
+ env: MONGOID_VERSION=6
22
+ - rvm: 2.5.1
23
+ env: MONGOID_VERSION=7
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0.0
4
+
5
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mongoid_localized_presence_validator.gemspec
6
+ gemspec
7
+
8
+ case version = ENV['MONGOID_VERSION'] || '~> 7.0'
9
+ when /7/ then gem 'mongoid', '~> 7.0'
10
+ when /6/ then gem 'mongoid', '~> 6.0'
11
+ else gem 'mongoid', version
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 asgerb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Mongoid Localized Presence Validator
2
+
3
+ [![Build Status](https://travis-ci.org/tomasc/mongoid_localized_presence_validator.svg)](https://travis-ci.org/tomasc/mongoid_localized_presence_validator) [![Gem Version](https://badge.fury.io/rb/mongoid_localized_presence_validator.svg)](http://badge.fury.io/rb/mongoid_localized_presence_validator) [![Coverage Status](https://img.shields.io/coveralls/tomasc/mongoid_localized_presence_validator.svg)](https://coveralls.io/r/tomasc/mongoid_localized_presence_validator)
4
+
5
+ This patch of the [mongoid](https://github.com/mongodb/mongoid) presence validator makes it easier to work with localized fields by adding the possibility to selectively validate the presence of certain locales or the app's default locale only.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mongoid_localized_presence_validator'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mongoid_localized_presence_validator
22
+
23
+ ## Usage
24
+
25
+ ```RUBY
26
+ class MyDoc
27
+ include Mongoid::Document
28
+ field :some_localized_field, type: String, localize: true
29
+
30
+ # Validate the presence of specific locales:
31
+ validates :some_localized_field, presence: %i[cs]
32
+
33
+ # Or just the default locale:
34
+ validates :some_localized_field, presence: :default_locale
35
+ end
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongoid_localized_presence_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mongoid_localized_presence_validator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "mongoid_localized_presence_validator/version"
2
+
3
+ require "mongoid_localized_presence_validator/patch"
@@ -0,0 +1,33 @@
1
+ require 'mongoid'
2
+
3
+ module MongoidLocalizedPresenceValidator
4
+ module Patch
5
+ def validate_each(document, attribute, value)
6
+ field = document.fields[document.database_field_name(attribute)]
7
+ return super(document, attribute, value) unless field.try(:localized?)
8
+
9
+ in_option = options.fetch(:in, nil)
10
+ with_option = options.fetch(:with, nil)
11
+
12
+ with_option = ::I18n.default_locale if with_option == :default_locale
13
+
14
+ locales = Array(in_option || with_option).select { |l| ::I18n.available_locales.include?(l.to_sym) }
15
+
16
+ if locales.present?
17
+ locales.each do |_locale|
18
+ _value = value.fetch(_locale.to_s, nil)
19
+ next unless not_present?(_value)
20
+ document.errors.add(
21
+ attribute,
22
+ :blank_in_locale,
23
+ options.merge(location: _locale)
24
+ )
25
+ end
26
+ else
27
+ super(document, attribute, value)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Mongoid::Validatable::PresenceValidator.send(:prepend, MongoidLocalizedPresenceValidator::Patch)
@@ -0,0 +1,3 @@
1
+ module MongoidLocalizedPresenceValidator
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "mongoid_localized_presence_validator/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mongoid_localized_presence_validator"
7
+ spec.version = MongoidLocalizedPresenceValidator::VERSION
8
+ spec.authors = ["Tomas Celizna", "Asger Behncke Jacobsen"]
9
+ spec.email = ["tomas.celizna@gmail.com", "a@asgerbehnckejacobsen.dk"]
10
+
11
+ spec.summary = "Selectively validate presence in Monogid localized fields"
12
+ spec.homepage = 'https://github.com/tomasc/mongoid_localized_presence_validator'
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'mongoid', '>= 6.0', '< 8.0'
23
+
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'coveralls'
26
+ spec.add_development_dependency 'database_cleaner', '>= 1.5.1'
27
+ spec.add_development_dependency 'guard'
28
+ spec.add_development_dependency 'guard-minitest'
29
+ spec.add_development_dependency 'minitest'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_localized_presence_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Celizna
8
+ - Asger Behncke Jacobsen
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2018-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '6.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '8.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '6.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '8.0'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: coveralls
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: database_cleaner
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.1
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.5.1
76
+ - !ruby/object:Gem::Dependency
77
+ name: guard
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: guard-minitest
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ - !ruby/object:Gem::Dependency
105
+ name: minitest
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ - !ruby/object:Gem::Dependency
119
+ name: rake
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ description:
133
+ email:
134
+ - tomas.celizna@gmail.com
135
+ - a@asgerbehnckejacobsen.dk
136
+ executables: []
137
+ extensions: []
138
+ extra_rdoc_files: []
139
+ files:
140
+ - ".coveralls.yml"
141
+ - ".gitignore"
142
+ - ".travis.yml"
143
+ - CHANGELOG.md
144
+ - Gemfile
145
+ - LICENSE.txt
146
+ - README.md
147
+ - Rakefile
148
+ - bin/console
149
+ - bin/setup
150
+ - lib/mongoid_localized_presence_validator.rb
151
+ - lib/mongoid_localized_presence_validator/patch.rb
152
+ - lib/mongoid_localized_presence_validator/version.rb
153
+ - mongoid_localized_presence_validator.gemspec
154
+ homepage: https://github.com/tomasc/mongoid_localized_presence_validator
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.7.6
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: Selectively validate presence in Monogid localized fields
178
+ test_files: []