Skip to content

Commit

Permalink
Add forwardable module and upgrade rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
dks17 committed Apr 5, 2020
1 parent 1a3e793 commit 2711e2a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 26 deletions.
24 changes: 15 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-10-23 10:17:29 -0400 using RuboCop version 0.75.1.
# on 2020-04-05 15:26:59 +0300 using RuboCop version 0.81.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -14,14 +14,15 @@ Bundler/DuplicatedGem:
- 'Gemfile'

# Offense count: 4
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 21
Max: 24

# Offense count: 10
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 292
Max: 290

# Offense count: 5
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -31,7 +32,7 @@ Metrics/MethodLength:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 104
Max: 105

# Offense count: 2
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
Expand All @@ -42,10 +43,10 @@ Naming/FileName:
- 'spec/mongoid-locker_spec.rb'

# Offense count: 1
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
# NamePrefixBlacklist: is_, has_, have_
# NameWhitelist: is_a?
# ForbiddenPrefixes: is_, has_, have_
# AllowedMethods: is_a?
# MethodDefinitionMacros: define_method, define_singleton_method
Naming/PredicateName:
Exclude:
Expand Down Expand Up @@ -84,11 +85,16 @@ RSpec/LeakyConstantDeclaration:
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 11
# Offense count: 10
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 3

# Offense count: 1
RSpec/SubjectStub:
Exclude:
- 'spec/support/delegated_methods_shared_examples.rb'

# Offense count: 2
Style/Documentation:
Exclude:
Expand All @@ -109,5 +115,5 @@ Style/NumericPredicate:
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Layout/LineLength:
Max: 250
16 changes: 11 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ script:

rvm:
- 2.3.8
- 2.4.5
- 2.5.4
- 2.6.2
- 2.4.7
- 2.5.7
- 2.6.6
- 2.7.1
- jruby-9.1.17.0
- jruby-9.2.6.0
- jruby-9.2.11.1

env:
- MONGOID_VERSION=5
Expand All @@ -23,7 +24,7 @@ env:

matrix:
include:
- rvm: 2.6.2
- rvm: 2.7.1
env:
- MONGOID_VERSION=7
- COVERAGE=true
Expand All @@ -39,7 +40,12 @@ matrix:
./cc-test-reporter upload-coverage;
fi
- rvm: ruby-head
env: MONGOID_VERSION=7
- rvm: jruby-head
env: MONGOID_VERSION=7
exclude:
- rvm: 2.7.1
env: MONGOID_VERSION=5
fast_finish: true
allow_failures:
- rvm: ruby-head
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

### 2.0.1 (Next)

* Your contribution here.
* [#86](https://github.com/mongoid/mongoid-locker/pull/86): Upgraded to RuboCop 0.81.0 - [@dks17](https://github.com/dks17).
* [#86](https://github.com/mongoid/mongoid-locker/pull/86): Fixed issue with `ruby` `delegate` method - [@dks17](https://github.com/dks17).
* [#86](https://github.com/mongoid/mongoid-locker/pull/86): Update Ruby and JRUby versions for Travis config - [@dks17](https://github.com/dks17).
* Your contribution here

### 2.0.0 (2019-10-23)

Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ group :development, :test do
gem 'pry-byebug', platforms: :mri

gem 'mongoid-danger', '~> 0.1.1'
gem 'rspec', '~> 3.8'
gem 'rubocop', '0.75.1'
gem 'rubocop-rspec'
gem 'rspec', '~> 3.9'
gem 'rubocop', '0.81.0'
gem 'rubocop-rspec', '1.38.1'
gem 'simplecov', require: false
end
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Document-level optimistic locking for MongoDB via Mongoid. Mongoid-Locker is an
**NOTE:** Please refer to [1-x-stable](https://github.com/mongoid/mongoid-locker/tree/1-x-stable) branch for `1.x.x` documentation. See the [UPGRADING](UPGRADING.md) guide and [CHANGELOG](CHANGELOG.md) for an overview of the changes.

[Tested](https://travis-ci.org/mongoid/mongoid-locker) against:
- MRI: `2.3.8`, `2.4.5`, `2.5.4`, `2.6.2`
- JRuby `9.1.17.0`, `9.2.6.0`
- MRI: `2.3.8`, `2.4.7`, `2.5.7`, `2.6.6`, `2.7.1`
- JRuby `9.1.17.0`, `9.2.11.1`
- Mongoid: `5`, `6`, `7`

See [.travis.yml](.travis.yml) for the latest test matrix.
Expand Down
5 changes: 4 additions & 1 deletion lib/mongoid/locker.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'forwardable'
require 'securerandom'

module Mongoid
Expand Down Expand Up @@ -103,6 +104,8 @@ def reset!

# @api private
def included(klass)
klass.extend(Forwardable) unless klass.ancestors.include?(Forwardable)

klass.extend ClassMethods
klass.singleton_class.instance_eval { attr_accessor(*MODULE_METHODS) }

Expand All @@ -114,7 +117,7 @@ def included(klass)
klass.backoff_algorithm = backoff_algorithm
klass.locking_name_generator = locking_name_generator

klass.delegate(*MODULE_METHODS, to: :class)
klass.def_delegators(klass, *MODULE_METHODS)
klass.singleton_class.delegate(*(methods(false) - MODULE_METHODS.flat_map { |method| [method, "#{method}=".to_sym] } - %i[included reset! configure]), to: self)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
require 'mongoid-locker'
Mongoid.load! File.join(File.dirname(__FILE__), 'database.yml')

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }

RSpec.configure do |config|
config.include LockerHelpers
Expand Down
6 changes: 2 additions & 4 deletions spec/support/locker_is_included_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@
end

it 'is chainable' do
expect do
criteria = model.where(_id: 1).locked.where(_id: 2)
expect(criteria.selector['_id']).to eq(2)
end.not_to raise_error
criteria = model.where(_id: 1).locked.where(_id: 2)
expect(criteria).to be_a(Mongoid::Criteria)
end

it 'selects locked document', :populate do
Expand Down

0 comments on commit 2711e2a

Please sign in to comment.