mongoid-embedded-errors 2.1.1 → 3.0.1

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
- SHA1:
3
- metadata.gz: cf676fc1f240e90f81b9e544ab757298062d73ca
4
- data.tar.gz: e6b81f36c32a1f8da79f99c248c69e9195cff91c
2
+ SHA256:
3
+ metadata.gz: 129c9a68d1921837c6cd5942d64272049bbc8fd8f756c29b0a825faa4c1d1527
4
+ data.tar.gz: 57c35bcc8813866051d60d5139e5901169b8478ce4d5be291e862e0bb0604e17
5
5
  SHA512:
6
- metadata.gz: d4278dd96bebd97e65cf8568f3856a84845edf20d75635686caa8b938fbf80b7e59f36ae49969c273850ee66fa1155b33ac68cb8a1e7eff5620871712fba5e7c
7
- data.tar.gz: b3af8d97147572f1e1210d0f7f0442f93a6347b75fbf792c6d773fe7332e5c3a90b3f0c50009660d875b9d509a074e6f37375bf550b03aebc94416206130fb68
6
+ metadata.gz: 857c87ef479cc4eb0ea15462f9c6386d2eff11987d0a0f895bc3429f14ffd9242fcbce2292bb7de04f2588481fa76bbdc1d0d9874bd2b6a4bcffc02b5149f22a
7
+ data.tar.gz: 3935c4a3d82f9e343b21f2272c05d4e8cf642191d79be7b89e82116220c76ba73b56b1e24885824e5fe6c9f17312a4f083cf2714a8356cb2768c0f1b4b57b488
@@ -1,5 +1,7 @@
1
1
  ---
2
- engines:
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
@@ -17,3 +17,5 @@ profile
17
17
  .rake_tasks~
18
18
  *.log.lck
19
19
  solr/
20
+ bin/
21
+ *.lock
@@ -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
- Rails:
16
- Enabled: true
17
-
18
- Style/FileName:
18
+ Naming/FileName:
19
19
  Exclude:
20
20
  - Appraisals
21
21
 
22
- Style/SpaceInsideHashLiteralBraces:
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: 15
31
+ Max: 40
32
32
 
33
33
  Metrics/AbcSize:
34
- Max: 20
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
- Style/ExtraSpacing:
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
@@ -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
- gem 'rspec'
7
- gem 'rake'
8
- gem 'database_cleaner'
9
- gem 'guard-rspec'
10
- gem 'appraisal'
11
- gem 'mutant-rspec'
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
  [![Code Climate](https://codeclimate.com/github/glooko/mongoid-embedded-errors/badges/gpa.svg)](https://codeclimate.com/github/glooko/mongoid-embedded-errors)
3
3
 
4
- Easily bubble up errors from embedded documents in Mongoid 3 and newer.
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.error.messages
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.error.messages
87
+ article.errors.messages
88
88
  {
89
89
  :name => ["can't be blank"],
90
90
  :summary => ["can't be blank"],
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler/setup'
3
5
 
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -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
- gemspec :path => "../"
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: "../"
@@ -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
- gemspec :path => "../"
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: "../"
@@ -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
- gemspec :path => "../"
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,2 +1,3 @@
1
- # rubocop:disable Style/FileName
1
+ # rubocop:disable Naming/FileName
2
2
  require 'mongoid/embedded_errors'
3
+ # rubocop:enable Naming/FileName
@@ -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
- # make sure that the alias only happens once:
8
- unless klass.instance_methods.include?(:errors_without_embedded_errors)
9
- klass.alias_method_chain(:errors, :embedded_errors)
10
- end
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
- [send(name)].flatten.reject(&:nil?).each_with_index do |rel, i|
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
- rel.errors.messages.each do |k, v|
27
- key = (metadata.relation == Mongoid::Relations::Embedded::Many ? "#{name}[#{i}].#{k}" : "#{name}.#{k}").to_sym
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[key] = v
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
- require 'mongoid/relations/embedded/in'
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 Mongoid::Relations::Macros::ClassMethods
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,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid; end
2
4
  module Mongoid::EmbeddedErrors
3
- VERSION = '2.1.1'.freeze
5
+ VERSION = '3.0.1'
4
6
  end
@@ -1,23 +1,32 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
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 = 'Easily bubble up errors from embedded '\
12
- 'documents in Mongoid.'
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('mongoid', '>=3.0')
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