mongoid-embedded-errors 2.1.1 → 3.0.1
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 +5 -5
- data/.codeclimate.yml +8 -5
- data/.gitignore +2 -0
- data/.rubocop.yml +15 -9
- data/.semaphore/semaphore.yml +46 -0
- data/Appraisals +4 -4
- data/CHANGELOG.md +27 -0
- data/Gemfile +8 -6
- data/README.md +3 -3
- data/Rakefile +2 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/mongoid_4.gemfile +10 -5
- data/gemfiles/mongoid_5.gemfile +10 -5
- data/gemfiles/mongoid_6.gemfile +10 -5
- data/gemfiles/mongoid_7.gemfile +16 -0
- data/lib/mongoid-embedded-errors.rb +2 -1
- data/lib/mongoid/embedded_errors.rb +23 -10
- data/lib/mongoid/embedded_errors/embedded_in.rb +10 -2
- data/lib/mongoid/embedded_errors/version.rb +3 -1
- data/mongoid-embedded-errors.gemspec +17 -8
- data/spec/lib/mongoid/embedded_errors_spec.rb +55 -4
- data/spec/spec_helper.rb +4 -2
- data/spec/support/models/annotation.rb +2 -0
- data/spec/support/models/article.rb +2 -0
- data/spec/support/models/page.rb +2 -0
- data/spec/support/models/section.rb +2 -0
- data/spec/support/mongoid.yml +1 -1
- metadata +55 -29
- data/Gemfile.lock +0 -168
- data/bin/_guard-core +0 -17
- data/bin/appraisal +0 -17
- data/bin/guard +0 -17
- data/bin/rake +0 -17
- data/bin/rspec +0 -17
- data/gemfiles/mongoid_3.gemfile +0 -11
- data/gemfiles/mongoid_3.gemfile.lock +0 -98
- data/gemfiles/mongoid_4.gemfile.lock +0 -110
- data/gemfiles/mongoid_5.gemfile.lock +0 -106
- data/gemfiles/mongoid_6.gemfile.lock +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 129c9a68d1921837c6cd5942d64272049bbc8fd8f756c29b0a825faa4c1d1527
|
4
|
+
data.tar.gz: 57c35bcc8813866051d60d5139e5901169b8478ce4d5be291e862e0bb0604e17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 857c87ef479cc4eb0ea15462f9c6386d2eff11987d0a0f895bc3429f14ffd9242fcbce2292bb7de04f2588481fa76bbdc1d0d9874bd2b6a4bcffc02b5149f22a
|
7
|
+
data.tar.gz: 3935c4a3d82f9e343b21f2272c05d4e8cf642191d79be7b89e82116220c76ba73b56b1e24885824e5fe6c9f17312a4f083cf2714a8356cb2768c0f1b4b57b488
|
data/.codeclimate.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
2
|
+
version: "2"
|
3
|
+
|
4
|
+
plugins:
|
3
5
|
rubocop:
|
4
6
|
enabled: true
|
5
7
|
bundler-audit:
|
@@ -8,10 +10,11 @@ engines:
|
|
8
10
|
enabled: true
|
9
11
|
duplication:
|
10
12
|
enabled: true
|
13
|
+
reek:
|
14
|
+
enabled: true
|
15
|
+
git-legal:
|
16
|
+
enabled: true
|
17
|
+
|
11
18
|
config:
|
12
19
|
languages:
|
13
20
|
- ruby
|
14
|
-
- javascript
|
15
|
-
ratings:
|
16
|
-
paths:
|
17
|
-
- Gemfile.lock
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -9,17 +9,17 @@ AllCops:
|
|
9
9
|
DisplayCopNames: true
|
10
10
|
Exclude:
|
11
11
|
- Guardfile
|
12
|
-
- gemfiles
|
12
|
+
- gemfiles/**/*
|
13
13
|
- bin/*
|
14
|
+
- vendor/bundle/**/*
|
15
|
+
- tmp/**/*
|
16
|
+
NewCops: enable
|
14
17
|
|
15
|
-
|
16
|
-
Enabled: true
|
17
|
-
|
18
|
-
Style/FileName:
|
18
|
+
Naming/FileName:
|
19
19
|
Exclude:
|
20
20
|
- Appraisals
|
21
21
|
|
22
|
-
|
22
|
+
Layout/SpaceInsideHashLiteralBraces:
|
23
23
|
EnforcedStyle: no_space
|
24
24
|
EnforcedStyleForEmptyBraces: no_space
|
25
25
|
SupportedStyles:
|
@@ -28,10 +28,16 @@ Style/SpaceInsideHashLiteralBraces:
|
|
28
28
|
|
29
29
|
Metrics/MethodLength:
|
30
30
|
CountComments: false # count full line comments?
|
31
|
-
Max:
|
31
|
+
Max: 40
|
32
32
|
|
33
33
|
Metrics/AbcSize:
|
34
|
-
Max:
|
34
|
+
Max: 40
|
35
|
+
|
36
|
+
Layout/LineLength:
|
37
|
+
Max: 120
|
38
|
+
|
39
|
+
Metrics/BlockLength:
|
40
|
+
Max: 50
|
35
41
|
|
36
42
|
Style/Documentation:
|
37
43
|
Description: 'Document classes and non-namespace modules.'
|
@@ -51,7 +57,7 @@ Style/MethodCalledOnDoEndBlock:
|
|
51
57
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
|
52
58
|
Enabled: true
|
53
59
|
|
54
|
-
|
60
|
+
Layout/ExtraSpacing:
|
55
61
|
Description: 'Do not use unnecessary spacing.'
|
56
62
|
Enabled: true
|
57
63
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
version: v1.0
|
2
|
+
name: mongoid-embedded-errors
|
3
|
+
agent:
|
4
|
+
machine:
|
5
|
+
type: e1-standard-2
|
6
|
+
os_image: ubuntu1804
|
7
|
+
|
8
|
+
blocks:
|
9
|
+
- name: Code Climate
|
10
|
+
task:
|
11
|
+
jobs:
|
12
|
+
- name: Code Climate
|
13
|
+
commands:
|
14
|
+
- checkout
|
15
|
+
- cache restore gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock),gems-$SEMAPHORE_GIT_BRANCH,gems-master
|
16
|
+
- bundle install --path vendor/bundle
|
17
|
+
- cache store gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock) vendor/bundle
|
18
|
+
- docker run --interactive --tty --rm --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /tmp/cc:/tmp/cc --volume /var/run/docker.sock:/var/run/docker.sock codeclimate/codeclimate analyze
|
19
|
+
|
20
|
+
- name: Unit tests
|
21
|
+
task:
|
22
|
+
jobs:
|
23
|
+
- name: Appraisal
|
24
|
+
commands:
|
25
|
+
- checkout
|
26
|
+
- cache restore gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock),gems-$SEMAPHORE_GIT_BRANCH,gems-master
|
27
|
+
- bundle install --path vendor/bundle
|
28
|
+
- cache store gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock) vendor/bundle
|
29
|
+
- cache restore appraisal-$SEMAPHORE_GIT_BRANCH-$(checksum gemfiles/*.gemfile.lock),appraisal-$SEMAPHORE_GIT_BRANCH,appraisal-master
|
30
|
+
- bundle exec appraisal
|
31
|
+
- cache store appraisal-$SEMAPHORE_GIT_BRANCH-$(checksum gemfiles/*.gemfile.lock) vendor/bundle
|
32
|
+
- sem-service start mongodb
|
33
|
+
- bundle exec appraisal rake test
|
34
|
+
|
35
|
+
- name: Mutant
|
36
|
+
task:
|
37
|
+
jobs:
|
38
|
+
- name: Mutant
|
39
|
+
commands:
|
40
|
+
- checkout
|
41
|
+
- cache restore gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock),gems-$SEMAPHORE_GIT_BRANCH,gems-master
|
42
|
+
- bundle install --path vendor/bundle
|
43
|
+
- cache store gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock) vendor/bundle
|
44
|
+
- sem-service start mongodb
|
45
|
+
- MUTANT=true bundle exec mutant --since "$SEMAPHORE_GIT_SHA~1" --include lib --require mongoid --use rspec "Mongoid::EmbeddedErrors*"
|
46
|
+
|
data/Appraisals
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
appraise 'mongoid-3' do
|
2
|
-
gem 'mongoid', '~> 3.0'
|
3
|
-
end
|
4
|
-
|
5
1
|
appraise 'mongoid-4' do
|
6
2
|
gem 'mongoid', '~> 4.0'
|
7
3
|
end
|
@@ -13,3 +9,7 @@ end
|
|
13
9
|
appraise 'mongoid-6' do
|
14
10
|
gem 'mongoid', '~> 6.0'
|
15
11
|
end
|
12
|
+
|
13
|
+
appraise 'mongoid-7' do
|
14
|
+
gem 'mongoid', '~> 7.0'
|
15
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
- TODO
|
8
|
+
|
9
|
+
## [v3.0.1] - 2020-09-29
|
10
|
+
### Added
|
11
|
+
- Started 🔎 tracking changes in a changelog!
|
12
|
+
- Mongoid 7 support
|
13
|
+
- Ruby 2.4 support by using `send` instead of `public_send` [#18]
|
14
|
+
|
15
|
+
### Removed
|
16
|
+
- Mongoid 3 support
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
- Updated style to fix Rubocop issues (as per included .rubocop.yml configuration file)
|
20
|
+
- Removed .lock files as these are not supposed to be included with gem source code
|
21
|
+
|
22
|
+
## [v3.0.0] - 2020-09-29 [YANKED]
|
23
|
+
- Yanked due to wrong dependencies in gemspec.
|
24
|
+
|
25
|
+
[Unreleased]: https://github.com/glooko/mongoid-embedded-errors/compare/v3.0.1...HEAD
|
26
|
+
[v3.0.1]: https://github.com/glooko/mongoid-embedded-errors/compare/v3.0.0...v3.0.1
|
27
|
+
[v3.0.0]: https://github.com/glooko/mongoid-embedded-errors/compare/f1ce0d8ed140de86c894b2fad7ad197504fefd5a...v3.0.0
|
data/Gemfile
CHANGED
@@ -3,9 +3,11 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in mongoid-embedded-errors.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
|
7
|
-
gem '
|
8
|
-
gem 'database_cleaner'
|
9
|
-
gem 'guard-rspec'
|
10
|
-
gem '
|
11
|
-
gem '
|
6
|
+
group :development do
|
7
|
+
gem 'appraisal'
|
8
|
+
gem 'database_cleaner'
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'mutant-rspec'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rspec'
|
13
|
+
end
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Mongoid::EmbeddedErrors
|
2
2
|
[](https://codeclimate.com/github/glooko/mongoid-embedded-errors)
|
3
3
|
|
4
|
-
Easily bubble up errors from embedded documents in Mongoid
|
4
|
+
Easily bubble up errors from embedded documents in Mongoid and newer.
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -62,7 +62,7 @@ If we were to create an invalid `Article` with an invalid `Page` and tried to va
|
|
62
62
|
article = Article.new(pages: [Page.new])
|
63
63
|
article.valid? # => false
|
64
64
|
|
65
|
-
article.
|
65
|
+
article.errors.messages
|
66
66
|
# => {:name=>["can't be blank"], :summary=>["can't be blank"], :pages=>["is invalid"]}
|
67
67
|
```
|
68
68
|
|
@@ -84,7 +84,7 @@ end
|
|
84
84
|
article = Article.new(pages: [Page.new(sections: [Section.new])])
|
85
85
|
article.valid? # => false
|
86
86
|
|
87
|
-
article.
|
87
|
+
article.errors.messages
|
88
88
|
{
|
89
89
|
:name => ["can't be blank"],
|
90
90
|
:summary => ["can't be blank"],
|
data/Rakefile
CHANGED
data/gemfiles/mongoid_4.gemfile
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "rspec"
|
6
|
-
gem "database_cleaner"
|
7
|
-
gem "guard-rspec"
|
8
|
-
gem "appraisal"
|
9
5
|
gem "mongoid", "~> 4.0"
|
10
6
|
|
11
|
-
|
7
|
+
group :development do
|
8
|
+
gem "appraisal"
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "guard-rspec"
|
11
|
+
gem "mutant-rspec"
|
12
|
+
gem "rake"
|
13
|
+
gem "rspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
data/gemfiles/mongoid_5.gemfile
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "rspec"
|
6
|
-
gem "database_cleaner"
|
7
|
-
gem "guard-rspec"
|
8
|
-
gem "appraisal"
|
9
5
|
gem "mongoid", "~> 5.0"
|
10
6
|
|
11
|
-
|
7
|
+
group :development do
|
8
|
+
gem "appraisal"
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "guard-rspec"
|
11
|
+
gem "mutant-rspec"
|
12
|
+
gem "rake"
|
13
|
+
gem "rspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
data/gemfiles/mongoid_6.gemfile
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "rspec"
|
6
|
-
gem "database_cleaner"
|
7
|
-
gem "guard-rspec"
|
8
|
-
gem "appraisal"
|
9
5
|
gem "mongoid", "~> 6.0"
|
10
6
|
|
11
|
-
|
7
|
+
group :development do
|
8
|
+
gem "appraisal"
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "guard-rspec"
|
11
|
+
gem "mutant-rspec"
|
12
|
+
gem "rake"
|
13
|
+
gem "rspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "mongoid", "~> 7.0"
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "appraisal"
|
9
|
+
gem "database_cleaner"
|
10
|
+
gem "guard-rspec"
|
11
|
+
gem "mutant-rspec"
|
12
|
+
gem "rake"
|
13
|
+
gem "rspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mongoid'
|
2
4
|
require 'mongoid/embedded_errors/version'
|
3
5
|
require 'mongoid/embedded_errors/embedded_in'
|
4
6
|
|
5
7
|
module Mongoid::EmbeddedErrors
|
6
8
|
def self.included(klass)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
return if klass.instance_methods.include?(:errors_without_embedded_errors)
|
10
|
+
|
11
|
+
klass.send :alias_method, :errors_without_embedded_errors, :errors
|
12
|
+
klass.send :alias_method, :errors, :errors_with_embedded_errors
|
11
13
|
end
|
12
14
|
|
13
15
|
def errors_with_embedded_errors
|
@@ -16,18 +18,29 @@ module Mongoid::EmbeddedErrors
|
|
16
18
|
# name is something like pages or sections
|
17
19
|
# if there is an 'is invalid' message for the relation then let's work it:
|
18
20
|
next unless Array(public_send(name)).any? { |doc| doc.errors.any? }
|
21
|
+
|
19
22
|
# first delete the unless 'is invalid' error for the relation
|
20
23
|
errs[name].delete 'is invalid'
|
21
24
|
errs.delete name.to_sym if errs[name].empty?
|
25
|
+
|
22
26
|
# next, loop through each of the relations (pages, sections, etc...)
|
23
|
-
[
|
24
|
-
# get each of their individual message and add them to the parent's errors:
|
27
|
+
[public_send(name)].flatten.reject(&:nil?).each_with_index do |rel, i|
|
25
28
|
next unless rel.errors.any?
|
26
|
-
|
27
|
-
|
29
|
+
|
30
|
+
# get each of their individual message and add them to the parent's errors:
|
31
|
+
rel.errors.each do |k, v|
|
32
|
+
relation = if Gem::Version.new(Mongoid::VERSION) >= Gem::Version.new('7.0.0')
|
33
|
+
metadata.class
|
34
|
+
else
|
35
|
+
metadata.relation
|
36
|
+
end
|
37
|
+
key = if relation.equal? EMBEDS_MANY
|
38
|
+
"#{name}[#{i}].#{k}"
|
39
|
+
else
|
40
|
+
"#{name}.#{k}"
|
41
|
+
end.to_sym
|
28
42
|
errs.delete(key)
|
29
|
-
errs
|
30
|
-
errs[key].flatten!
|
43
|
+
errs.add key, v if v.present?
|
31
44
|
end
|
32
45
|
end
|
33
46
|
end
|
@@ -1,6 +1,14 @@
|
|
1
|
-
|
1
|
+
if Gem::Version.new(Mongoid::VERSION) >= Gem::Version.new('7.0.0')
|
2
|
+
require 'mongoid/association/embedded/embedded_in'
|
3
|
+
ASSOCIATION = Mongoid::Association::Macros::ClassMethods
|
4
|
+
EMBEDS_MANY = Mongoid::Association::Embedded::EmbedsMany
|
5
|
+
else
|
6
|
+
require 'mongoid/relations/embedded/in'
|
7
|
+
ASSOCIATION = Mongoid::Relations::Macros::ClassMethods
|
8
|
+
EMBEDS_MANY = Mongoid::Relations::Embedded::Many
|
9
|
+
end
|
2
10
|
|
3
|
-
module
|
11
|
+
module ASSOCIATION
|
4
12
|
alias embedded_in_without_embedded_errors embedded_in
|
5
13
|
def embedded_in(*args)
|
6
14
|
relation = embedded_in_without_embedded_errors(*args)
|
@@ -1,23 +1,32 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'mongoid/embedded_errors/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |gem|
|
7
8
|
gem.name = 'mongoid-embedded-errors'
|
8
|
-
gem.version = Mongoid::EmbeddedErrors::VERSION
|
9
|
+
gem.version = Mongoid::EmbeddedErrors::VERSION.dup
|
9
10
|
gem.authors = ['Mark Bates', 'Kristijan Novoselić']
|
10
11
|
gem.email = ['mark@markbates.com', 'kristijan@glooko.com']
|
11
|
-
gem.description = '
|
12
|
-
'documents
|
12
|
+
gem.description = 'Embedded documents in Mongoid can be really useful. '\
|
13
|
+
'However, when one of those embedded documents is '\
|
14
|
+
'invalid, Mongoid does not say which validation has '\
|
15
|
+
'failed. Instead of just saying that an embedded '\
|
16
|
+
'document is invalid, this gem modifies Mongoid '\
|
17
|
+
'behavior so it explicitly provides validation errors '\
|
18
|
+
'on a per-field basis for embedded documents, the '\
|
19
|
+
'same way it does for parent documents.'
|
13
20
|
gem.summary = 'Easily bubble up errors from embedded '\
|
14
21
|
'documents in Mongoid.'
|
15
|
-
gem.homepage = ''
|
16
|
-
|
22
|
+
gem.homepage = 'https://github.com/glooko/mongoid-embedded-errors'
|
23
|
+
gem.licenses = ['MIT']
|
17
24
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
25
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
19
26
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
27
|
gem.require_paths = ['lib']
|
21
28
|
|
22
|
-
gem.add_dependency
|
29
|
+
gem.add_dependency 'mongoid', '>=4.0', '<8.0.0'
|
30
|
+
gem.add_development_dependency 'rubocop', '~> 0.92'
|
31
|
+
gem.add_development_dependency 'rubocop-rspec', '~> 1.43'
|
23
32
|
end
|